Fizz Buzz in CSS
susam.net
Fizz Buzz in CSS
1–10 of 25 posts
Re: Fizz Buzz in CSS
#2Re: Fizz Buzz in CSS
#3 li:nth-child(3n), li:nth-child(5n) { list-style: none }
li:nth-child(3n)::before { content: "Fizz" }
li:nth-child(5n)::after { content: "Buzz" }
Example: https://susam.net/code/web/css-fizz-buzz-ol.html $ curl -sS https://susam.net/code/web/css-fizz-buzz-ol.html | sed -n '/none/,/after/p' | tr -d '[:space:]'
li:nth-child(3n),li:nth-child(5n){list-style:none}li:nth-child(3n)::before{content:"Fizz"}li:nth-child(5n)::after{content:"Buzz"}
$ curl -sS https://susam.net/code/web/css-fizz-buzz-ol.html | sed -n '/none/,/after/p' | tr -d '[:space:]' | wc -c
129
But I don't quite like how misaligned the numbers and the words look in this version. Correcting that would call for extra code that would cancel out the characters saved.Re: Fizz Buzz in CSS
#4I love this, it's a very clever and funny way to solve the problem. Makes me think about how there are infinite routes from A to B, some more scenic and whimsical than others.. as well as all the people I've met along the way who would be so pissed and pedantic about how this isn't a "real solution" LOL
Re: Fizz Buzz in CSS
#5Re: Fizz Buzz in CSS
#6A shorter solution is possible with an ordered list ( ) if we're willing to ignore the untidy output: li:nth-child(3n), li:nth-child(5n) { list-style: none } li:nth-child(3n)::before { content: "Fizz" } li:nth-child(5n)::after { content: "Buzz" } Example: https://susam.net/code/web/css-fizz-buzz-ol.html $ curl -sS https://susam.net/code/web/css-fizz-buzz-ol.html | sed -n '/none/,/after/p' | tr -d '[:space:]' li:nth-c…
list-style-position: inside;Re: Fizz Buzz in CSS
#7A shorter solution is possible with an ordered list ( ) if we're willing to ignore the untidy output: li:nth-child(3n), li:nth-child(5n) { list-style: none } li:nth-child(3n)::before { content: "Fizz" } li:nth-child(5n)::after { content: "Buzz" } Example: https://susam.net/code/web/css-fizz-buzz-ol.html $ curl -sS https://susam.net/code/web/css-fizz-buzz-ol.html | sed -n '/none/,/after/p' | tr -d '[:space:]' li:nth-c…
list-style-position: inside;
I mean, the solution in the original post is 152 characters long.
The based solution is 129 characters long. Shorter but uglier.
If we add your correction, we get neater output, which is nice, but it comes at the cost of 30 additional characters in the minified code thereby making the solution 159 characters long.
li { list-style-position: inside }
li:nth-child(3n), li:nth-child(5n) { list-style: none }
li:nth-child(3n)::before { content: "Fizz" }
li:nth-child(5n)::after { content: "Buzz" }Re: Fizz Buzz in CSS
#8I love this, it's a very clever and funny way to solve the problem. Makes me think about how there are infinite routes from A to B, some more scenic and whimsical than others.. as well as all the people I've met along the way who would be so pissed and pedantic about how this isn't a "real solution" LOL
Re: Fizz Buzz in CSS
#9A shorter solution is possible with an ordered list ( ) if we're willing to ignore the untidy output: li:nth-child(3n), li:nth-child(5n) { list-style: none } li:nth-child(3n)::before { content: "Fizz" } li:nth-child(5n)::after { content: "Buzz" } Example: https://susam.net/code/web/css-fizz-buzz-ol.html $ curl -sS https://susam.net/code/web/css-fizz-buzz-ol.html | sed -n '/none/,/after/p' | tr -d '[:space:]' li:nth-c…
Re: Fizz Buzz in CSS
#10p{counter-increment:n} p:not(:nth-child(5n)):before{content:counter(n)} p:nth-child(3n):before{content:"Fizz"} p:nth-child(5n):after{content:"Buzz"}