html - How to Make Tabs In CSS? -
i want make tabs contents using css. have made custom tab style can't make content css. can tell me how can ?
css:
.tabs { list-style: none; margin: 0; padding: 0; position: relative; } .tabs li { margin: 0 2px; padding: 10px; cursor: pointer; background: white; display: inline-block; } .tabs li:not(.active):hover { background: #ccc; border-top-right-radius: 4px; border-top-left-radius: 4px; } .tabs li > { text-decoration: none; color: gray } .tabs li.active { z-index: 1000; border-top-right-radius: 4px; border-top-left-radius: 4px; border: 1px solid #ccc; border-bottom-color: #fff; color: grey; cursor: default; } .tabs:after { position: absolute; content: ""; width: 100%; z-index: 1; bottom: 0; left:0; border-bottom: 1px solid #ddd; } .tabs:before { z-index: 1; } html:
<ul class="tabs"> <li class="active"><a href="#tab1">home</a></li> <li><a href="#tab2">contact</a></li> <li><a href="#tab3">services</a></li> </ul> fiddle
there multiple way implement "pure css" tab control. example, i've modified html part of jsfiddle add <div> content within <li> markup. added 2 bits of styling acually hide inactive tabs.
/* content specific css tabs*/ .tabs li div { display: none; } /* content specific css active tab */ .tabs li.active div { display: block; position:absolute; left:0px; } i changed idea of having <a> header links, wouldn't carry state in "pure css". removed .active rendered useless using radio inputs (to force 1 active tab @ time). broken repercussion change on active tab's content css selector. instead of previous : .tabs li.active div, it's following :
.tabs input[name=tabs]:checked ~ div that translated : select divs sibling input tag named tabs checked.
you pretty close implementation, main error can explained neglecting following statement : preserving state in pure css requires radio or checkbox inputs.
cheers! :-)
Comments
Post a Comment