Skip to content

Instantly share code, notes, and snippets.

@Leko
Last active December 18, 2015 22:39
Show Gist options
  • Save Leko/5856060 to your computer and use it in GitHub Desktop.
Save Leko/5856060 to your computer and use it in GitHub Desktop.
CSSでのFizzBuzzをSassのmixin化してみました。
@mixin fizzbuzz_nth($fs: 18px) {
li {
font-size: $fs;
display: inline-block;
}
li:nth-child(3n), li:nth-child(5n) {
font-size: 0;
}
li:nth-child(3n):before {
font-size: $fs;
content: "Fizz";
}
li:nth-child(5n):after {
font-size: $fs;
content: "Buzz";
}
}
.fizzbuzz-n {
@include fizzbuzz_nth();
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>FizzBuzz</title>
<!--↑のCSS読み込み-->
</head>
<body>
<div class="fizzbuzz-n">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<!--長いので省略。ただの連番のliが続きます-->
<li>100</li>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment