News for hackers. Stuff that matters.
Re:Solving FizzBuzz with CSS by danab on Monday May 07, 2012 @11:39AM (#3939442)
Correct 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";
  }
Re:Solving FizzBuzz with CSS by jackiebalzer on Monday May 07, 2012 @11:45AM (#3939475)
Correct, 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.

Re:Solving FizzBuzz with CSS by jontro on Monday May 07, 2012 @12:35PM (#3939715)
This should also work:

div:nth-child(3n):after { content: ""; }

div:nth-child(3n):before { content: "fizz"; }

div:nth-child(5n):after { content: "buzz"; }

Re:Solving FizzBuzz with CSS by danab on Monday May 07, 2012 @12:41PM (#3939751)
I retract my answer in favor of this. Clever.
Re:Solving FizzBuzz with CSS by Sivart13 on Monday May 07, 2012 @04:33PM (#3940845)
I think your answer is a lot more readable, though. I have to squint at jontro's version for a while before determining that it'll actually product the string "fizzbuzz".
Re:Solving FizzBuzz with CSS by Flam on Monday May 07, 2012 @10:41PM (#3941975)
Brilliant.
Re:Solving FizzBuzz with CSS by eykanal on Monday May 07, 2012 @11:41AM (#3939444)
Heh... how this looks in IE 8: http://i.stack.imgur.com/Fz3jT.png
Re:Solving FizzBuzz with CSS by scribblemacher on Monday May 07, 2012 @11:44AM (#3939461)
To be fair, isn't that what most sites look like in IE8?
Re:Solving FizzBuzz with CSS by jenius on Monday May 07, 2012 @11:59AM (#3939528)
hahah win.
Re:Solving FizzBuzz with CSS by steelaz on Monday May 07, 2012 @12:27PM (#3939672)
To be fair, IE8 was released on March 2009 (according to wiki), Chrome at that time was v1.0 and Firefox was v3.0.
Re:Solving FizzBuzz with CSS by catch23 on Monday May 07, 2012 @01:27PM (#3939972)
Usually 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.
Re:Solving FizzBuzz with CSS by scribblemacher on Monday May 07, 2012 @04:43PM (#3940891)
Not to mention those of us in a workplace still using XP (and thus unable to upgrade past IE8).
Re:Solving FizzBuzz with CSS by gordian on Monday May 07, 2012 @07:39PM (#3941449)
All 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.

Re:Solving FizzBuzz with CSS by scrame on Monday May 07, 2012 @08:10PM (#3941549)
Corporate environments sometimes lock down their computers completely, and don't give admin/install privileges, let alone OS updates.

So yes, "stuck".

Re:Solving FizzBuzz with CSS by gordian on Thursday May 17, 2012 @06:53PM (#3989544)
The dev community should not be at the mercy of incompetent sysadmins. Evolve or die. Such is life. Such is business.
Re:Solving FizzBuzz with CSS by bawllz on Monday May 07, 2012 @09:52PM (#3941804)
good thing you don't need to install chrome to run it then!
Re:Solving FizzBuzz with CSS by alainbryden on Monday May 07, 2012 @12:08PM (#3939572)
No rest until CSS is Turing complete.
Re:Solving FizzBuzz with CSS by espo on Monday May 07, 2012 @12:33PM (#3939702)
You mean like this CSS-implementation of Rule 110? http://eli.fox-epste.in/rule110-full.html
Re:Solving FizzBuzz with CSS by thisisblurry on Monday May 07, 2012 @02:07PM (#3940165)
For those who tried this in Chrome, like me, it won't work :(

Try it in Firefox instead.

Re:Solving FizzBuzz with CSS by djhworld on Monday May 07, 2012 @07:22PM (#3941402)
Chrome didn't work for me either, firefox was fine
Re:Solving FizzBuzz with CSS by khwang on Monday May 07, 2012 @05:45PM (#3941106)
Worked fine for me.
Re:Solving FizzBuzz with CSS by bawllz on Monday May 07, 2012 @09:54PM (#3941809)
ditto
Re:Solving FizzBuzz with CSS by thekungfuman on Monday May 07, 2012 @11:27AM (#3939368)
Goes to show how many (greatly needed) programmatic features CSS is adding. Also shows that some people love a creative way to attack a problem.
Re:Solving FizzBuzz with CSS by its_so_on on Monday May 07, 2012 @12:20PM (#3939630)
As God is my witness, CSS will need to be split into a presentation language and a logic language. /s
Re:Solving FizzBuzz with CSS by evincarofautumn on Monday May 07, 2012 @10:02PM (#3941836)
You 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?
Re:Solving FizzBuzz with CSS by DavidAbrams on Tuesday May 08, 2012 @02:49AM (#3942563)
Goes to show what a hack-riddled mess Web presentation still is.
Re:Solving FizzBuzz with CSS by DavidAbrams on Tuesday May 08, 2012 @02:48AM (#3942557)
Is this some regional drinking game? Like Three-Man?