Skip to content

Instantly share code, notes, and snippets.

@sperelson
Last active August 29, 2015 14:21
Show Gist options
  • Save sperelson/98070ba0e80186e908d4 to your computer and use it in GitHub Desktop.
Save sperelson/98070ba0e80186e908d4 to your computer and use it in GitHub Desktop.
Pure CSS FizzBuzz
Based on the implementation from <a href="http://joseph.mx/blog/2015/05/12/Pure-CSS-FizzBuzz.html">http://joseph.mx/blog/2015/05/12/Pure-CSS-FizzBuzz.html</a><br />
I just added the numbers, which was easier than I first thought because counters exist: <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Counters">https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Counters</a>
<div class="container">
</div>
for(i = 0; i < 30; i++){
$(".container").append("<div class='fizzbuzz'><span></span></div>")
}
body {
counter-reset: fizzbuzz;
}
.fizzbuzz {
width: 70px;
height: 35px;
background: black;
margin: 20px;
float: left;
color: white;
text-align: center;
padding-top: 15px;
counter-increment: fizzbuzz;
}
.fizzbuzz span::before {
content: counter(fizzbuzz);
}
.fizzbuzz:nth-of-type(3n){
background: green;
}
.fizzbuzz:nth-of-type(3n) span {
display: none;
}
.fizzbuzz:nth-of-type(3n)::before{
content: "fizz";
}
.fizzbuzz:nth-of-type(5n){
background: blue;
}
.fizzbuzz:nth-of-type(5n) span {
display: none;
}
.fizzbuzz:nth-of-type(5n)::before{
content: "buzz";
}
.fizzbuzz:nth-of-type(3n).fizzbuzz:nth-of-type(5n){
background: orange !important;
}
.fizzbuzz:nth-of-type(3n).fizzbuzz:nth-of-type(5n) span {
display: none;
}
.fizzbuzz:nth-of-type(3n).fizzbuzz:nth-of-type(5n)::before{
content: "fizzbuzz"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment