Home > Web Front-end > CSS Tutorial > Code for tab implementation in css

Code for tab implementation in css

不言
Release: 2018-08-03 09:28:26
Original
2152 people have browsed it

The content of this article is about the code for tab implementation in CSS. It has good reference value. I hope it can help friends in need.

#title {
height: 30px;
width: 400px;
}
#title li {
float: left;
list-style-type: none;
height: 30px;
width: 132px;
line-height: 30px;
text-align: center;
margin-right: 1px;
}
#title a {
text-decoration: none;
display: block;
width: auto;
color: black;
}
#title a span{
display: block;
padding: 0 15px 0 15px;
}
#title #tag1 a:hover {
color: #ffffff;
background-color: #16a085;
width: auto;
}
#title #tag2 a:hover {
color: #ffffff;
background-color: #16a085;
width: auto;
}
#title #tag3 a:hover {
color: #ffffff;
width: auto;
background-color: #16a085;
}
#title a .selectspan1,#title a .selectspan2,#title a .selectspan3 {
display: block;
background-color: #84AF9B;
padding: 0 15px 0 15px;
}
#content ul {margin: 10px;}
#content li {margin: 5px; }
#content {
height: 300px;
padding-top: 20px;
}
.content1,.content2,.content3 {
border-top-color:#84AF9B ;
border-top-style:solid;
}
.hidecontent {display:none;}
Copy after login
function switchTag(tag,content)
{
//    alert(tag);
//    alert(content);
for(i=1; i <4; i++)
{
if ("tag"+i==tag)
{
document.getElementById(tag).getElementsByTagName("a")[0].className="selectli"+i;
document.getElementById(tag).getElementsByTagName("a")[0].getElementsByTagName("span")
[0].className="selectspan"+i;
}else{
document.getElementById("tag"+i).getElementsByTagName("a")[0].className="";
document.getElementById("tag"+i).getElementsByTagName("a")[0].getElementsByTagName("span")
[0].className="";
}
if ("content"+i==content)
{
document.getElementById(content).className="";
}else{
document.getElementById("content"+i).className="hidecontent";
}
document.getElementById("content").className=content;
}
}
Copy after login
<div id="title">
                <ul>
                <li id="tag1"><a href="#" onclick="switchTag(&#39;tag1&#39;,&#39;content1&#39;);this.blur();"class="selectli1"><span
                class="selectspan1">租</span></a></li>
                <li id="tag2"><a href="#" onclick="switchTag(&#39;tag2&#39;,&#39;content2&#39;);this.blur();"><span>优</span></a></li>
                <li id="tag3"><a href="#" onclick="switchTag(&#39;tag3&#39;,&#39;content3&#39;);this.blur();"><span>产</span></a></li>
                </ul>
            </div>
            <div id="content" class="content1"></div>
<div id="content2" class="hidecontent">22222</div>
                <div id="content3" class="hidecontent">3333333</div>
Copy after login

Recommended related articles:

What are the CSS styles? Summary of three methods of css style sheet (with code)

How to use CSS to achieve the dynamic effect of color-changing rotation animation

The above is the detailed content of Code for tab implementation in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template