Created
December 28, 2015 13:11
-
-
Save terrierscript/c376e0c8fcae666df244 to your computer and use it in GitHub Desktop.
Sassの@eachを使ってタブ実装をするCSS思いついた ref: http://qiita.com/inuscript/items/295616708cc18c255995
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="list1"> | |
<li>AAAA</li> | |
<li class="active">BBBB</li> | |
<li>CCCC</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#list1{ | |
li{ | |
cursor: pointer; | |
display: inline-block; | |
border: 1px gray solid; | |
border-bottom: 0px; | |
padding: 10px; | |
} | |
.active{ | |
background: #ccb; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- var activeTab = "bbbb" | |
- var tabs = ["aaaa", "bbbb", "cccc"] | |
ul#list1 | |
each tab,i in tabs | |
li(class=(tab == activeTab ? "active" : "" ))= tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="list2" class="active-bbbb"> <!-- 親で指定する --> | |
<li class="tab-aaaa">AAAA</li> | |
<li class="tab-bbbb">BBBB</li> | |
<li class="tab-cccc">CCCC</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#list1{ | |
li{ | |
cursor: pointer; | |
display: inline-block; | |
border: 1px gray solid; | |
border-bottom: 0px; | |
padding: 10px; | |
} | |
$tabs: aaaa, bbbb, cccc; // 利用するタブを並べる | |
@each $tab in $tabs{ | |
&.active-#{$tab}{ | |
.tab-#{$tab}{ // 親と一致したらactive化する | |
background: #ccb; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#list1 li { | |
cursor: pointer; | |
display: inline-block; | |
border: 1px gray solid; | |
border-bottom: 0px; | |
padding: 10px; | |
} | |
#list1.active-aaaa .tab-aaaa { | |
background: #ccb; | |
} | |
#list1.active-bbbb .tab-bbbb { | |
background: #ccb; | |
} | |
#list1.active-cccc .tab-cccc { | |
background: #ccb; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- var activeTab = "bbbb" | |
- var tabs = ["aaaa", "bbbb", "cccc"] | |
ul#list2(class="active-" + activeTab) | |
each tab,i in tabs | |
li(class="tab-" + tab)= tab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment