8 ms·
Solving FizzBuzz with CSS
- deleted 14y ago[deleted]
- DavidAbrams 14y agoIs this some regional drinking game? Like Three-Man?
- thekungfuman 14y agoGoes to show how many (greatly needed) programmatic features CSS is adding. Also shows that some people love a creative way to attack a problem.
- DavidAbrams 14y agoGoes to show what a hack-riddled mess Web presentation still is.
- its_so_on 14y agoAs God is my witness, CSS will need to be split into a presentation language and a logic language. /s
- evincarofautumn 14y agoYou know, that’s not such an outlandish claim. CSS is accumulating features that seem to me completely out of place in a styling language. Then again, HTML isn’t perfect, nor JavaScript, nor PHP or any language—but we still get stuff done with them, so who am I to complain?
- deleted 14y ago[deleted]
- danab 14y agoCorrect me if I'm wrong, but I don't believe you need any of the :not statements, and instead or (3n) and (5n) you can just use 15n for the 'fizzbuzz'. The cascade of the CSS will take care of the cases the div is a 'fizzbuzz'. Sorry I can't post the example, Dabblet is working strangely for me this morning. CSS that should work: /** * FizzBuzz with CSS */ body { counter-reset: fizzbuzz; } div { width: 100px; height: 20px; background: #ddd; margin: 0 0 10px; } div::after { content: counter(fizzbuzz); counter-increment: fizzbuzz; } div:nth-child(3n)::after { content: "fizz"; } div:nth-child(5n)::after { content: "buzz"; } div:nth-child(15n)::after { content: "fizzbuzz"; }
- jackiebalzer 14y agoCorrect, you don't need the :nots as long as the CSS is in that order, since the :after content would be overridden correctly. You would need them if you changed the order of the statements. I started the experiment using background color instead of "fizz", border color instead of "buzz", and box-shadow instead of "fizzbuzz" which necessitated the need for :nots since the properties weren't overriding.
- jontro 14y agoThis should also work: div:nth-child(3n):after { content: ""; } div:nth-child(3n):before { content: "fizz"; } div:nth-child(5n):after { content: "buzz"; }
- eykanal 14y agoHeh... how this looks in IE 8: http://i.stack.imgur.com/Fz3jT.png http://i.stack.imgur.com/Fz3jT.png
- scribblemacher 14y agoTo be fair, isn't that what most sites look like in IE8?
- jenius 14y agohahah win.
- steelaz 14y agoTo be fair, IE8 was released on March 2009 (according to wiki), Chrome at that time was v1.0 and Firefox was v3.0.
- catch23 14y agoUsually IE8 users are stuck in IE8 unless they let the OS upgrade their browser, so most of the users that started with IE8 are still stuck in 2009. Chrome/FF users tend to have less issues with upgrades.
- scribblemacher 14y agoNot to mention those of us in a workplace still using XP (and thus unable to upgrade past IE8).
- gordian 14y agoAll horrible arguments. "Stuck?" Download a real browser. IE8 viewers expect devs to slow progress or cater to them would be like horse and buggy drivers from days of yore lobbying to prevent cars from going faster than horses. Stop complaining, get off your horse and get a (free) car. Encourage your clients to do likewise.
- alainbryden 14y agoNo rest until CSS is Turing complete.
- espo 14y agoYou mean like this CSS-implementation of Rule 110? http://eli.fox-epste.in/rule110-full.html http://eli.fox-epste.in/rule110-full.html
- thisisblurry 14y agoFor those who tried this in Chrome, like me, it won't work :( Try it in Firefox instead.