Hacker News new | past | comments | ask | show | jobs | submit login
Single Element MacBook Pro with CSS (codepen.io)
243 points by michaelkscott on Aug 15, 2012 | hide | past | favorite | 65 comments



If you add .macbook {zoom:4;} you can see how the detail is done. Basically you use lots of box-shadows to give you elements to glue together. The details on the front are not actually solid lines, but a collection of circles side by side.

That's when you realise this technique is a bit flawed - you can't actually scale the element and keep the detail, you'd be better off with an image. Not to take anything away from it though. It's good work.


You could actually scale it if I had have used ems/rems instead of px. But you are right, an image is the way to go for production.


Cool, and I'm glad that someone is demonstrating a way to use CSS3 to create graphics in a way that doesn't require extra markup. One of the biggest problems with CSS3 is that, in a twist of irony, it's image composition power entices developers into adding markup to hang the CSS off of. This ends up complicating the markup merely to generate an image, which is a mistake.

This technique, on the other hand, using the :before and :after selectors shows the right way to use CSS3 image composition, if you choose to do it. This example should be shouted from the hilltops to all front-end web devs.


This should be an SVG. Using box-shadows to create shapes is not only confusing but really, really performance-draining.

(not to be a downer, it's incredibly impressive, but not something you should do in production code)


Spot on. I clearly state in the description field that it is only an experiment.


SVG fills me with dread. Canvas, maybe.


Why does SVG fill you with dread? (Honest question.)


Probably because of "wall-of-xml" syndrome.

Of course, SVG should be generated by tools rather than typed by hackers, but people tend to forget that.


There really should be a warning on all these demos, something like: "Don't actually draw with css in the wild, you'll break the web."


I wouldn't worry too much.

Drawing in CSS like this isn't as simple as dropping jQuery on the page.

If there was a jQuery plugin to automate this process from image to css, then we should worry!


How so?


I think more than "you'll break the web" the issue is that it's almost never the right choice to make when compared to using more traditional techniques (e.g. images or svgs). Also it won't work in older browsers.


Just try visiting the page on iPad and zoom. You'll know.

(Hint: browser crash)


Browser crash?

Better fire up IDA!


Zoomed just fine on my ipad


http://codepen.io/anon/pen/vyHwk

one line difference and you have the non-glossy screen version.


That's a white MacBook for me, but still glossy.


http://codepen.io/anon/full/lCAEc

Missed a spot! This is true non-glossy.


Wow. There have been many of these "Look what I can do in CSS" articles lately, and frankly, they are normally quite boring. However this is the first time I have ever gone "wow". Very impressive. Quite useless really, but good work.


A pure hack if there ever was one.


Very cool. Not sure why I'd ever need this, but it's impressive that it can be done. Congratulations on making something awesome.


And now we've got a Macbook Air!

http://codepen.io/anon/pen/kqALB


Here I tried to create all MacBooks http://codepen.io/FWeinb/pen/dEnbz


It's been well established that you can achieve just about any icon purely with CSS. Why is this getting so many upvotes?


It's been well established that you can paint just about anything with oil paints. Why do people go to art museums?


Not sure that Hacker News is comparable to an art museum. But point taken.


Legos might have been the better example :)


G'day, I'm the guy that made it. I agree with your comment completely, I had one pretty big constraint though; one element allowed. I'd like to think that is why it is getting upvoted.


Take it you're an Aussie. In which case, more power to you (I'm in Newcastle). Lovely icon.


I am; Melbourne based. Thanks!


Because Apple, maybe?


While undoubtedly impressive, I think using css :before and :after kind of defeats the point of 'single element'


No it doesn't really, it keeps your HTML clean. Sure, there's better ways of getting a MacBook into your webpage, but this definitely shows the power of the :before and :after selectors.


It may keep your HTML clean, but it makes your CSS messy!


That's why I said there's better ways of getting a MacBook into your webpage. But my point still stands, :before and :after are very powerful.


I'd much rather have clean, reusable HTML. CSS you can use preprocessors to abstract away the messiness.


Aren't you using templates and macros for HTML already?


Changing how the HTML macros expand likely ends up requiring CSS changes (in practice, though not necessarily in a theoretically-ideal code base). One change in two places, vs one change in one place.


No, I typically write entirely client side applications.


Any reading recommendations for someone who isn't?


> No it doesn't really, it keeps your HTML clean.

You can also keep your kitchen clean by stuffing all the dirty stuff into the cupboards.


The thing to keep in mind is that the use of pseudo-elements keeps the style separate from the content. In terms of practicality, there isn't much; I did this as an experiment in semantics and the latest CSS properties and techniques.


Here is the comparison between different web browsers. Note that the image does not even load in IE8, so it is not included.

http://i.imgur.com/ibi7I.png


Impressive. While I'm generally familiar with CSS I haven't delved into the icon logo stuff yet. I'm toying with the idea of trying to create JS/CSS-based country/state maps with customizable mouseover/onclick functionality, since there aren't really any good free versions available (that I've found). This kind of stuff inspires me that it might be possible, though I have no idea how hard it would be to create geographically-shaped elements.


You should look into SVG for doing detailed graphics. There are a number of libraries for making it easier to work with, Raphael came to mind because I remembered this demo: http://raphaeljs.com/australia.html


D3.js


And because I'm a content-management geek: http://codepen.io/anon/pen/wxytJ


Looks like it's probably even smaller than the equivalent SVG would be. Wish I had a use for it.


Very nice!

Add: text-align: center; line-height: 100px;

to the .macbook css, so you can add text to the screen ;)


Chrome-only? Doesn't appear to work in Firefox nightly.

Edit: Somehow my fault. Works with new profile in FF14. Curiously doesn't work in my standard profile in Aurora or Nightly even with plugins disabled.


Works for me in Firefox 14.


even works on Android nightlies


This one has a GPS like device made of only CSS: http://geeksigner.com/clients/egl/


Wow, this markup language that provides shapes, positions, colors, gradients, and transparency can be used to create images!


Does anyone else think the front is too wide for that perspective? My only criticism.


+1 the left and right should be -15px instead of -22 and the led light should be moved a bit to the left and it looks perfect imo.

Nonetheless, I find it quite ingenious! Bravo


I simply eyeballed an image rather than working to scale. As it is just an experiment, I'm not too fussed by the incorrect dimensions.


Dw, I think its brilliant and I upvoted. The perspective just gets to me is all :)



Were it a photo, that would only depend on the focal length of the lens i.e. a super-wide-angle lens could make the front even wider relative to the screen.


Pfft, thats not a retina display.


added the macbook pro logo to top it off. hope you dont mind :D


Very cool. Nice work.


Are you a wizard?


This is not reddit.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: