我有两个不同的标签,其中包含以下HTML代码,
.tabs{
margin-left: 10px;
color: black;
width: 100%;
}
.all-tab{
margin-left: 15px;
}
.first-tab{
margin-left: 0%;
}
.tab {
position: relative;
list-style: none;
display: inline-block;
width: 13%;
}
.tab-left {
float: left;
width: 17px;
height: 30px;
border-radius: 1px;
margin-left: 5px;
background-color: #686868;
transform: skew(-20deg);
}
.tab-centre {
float: left;
margin-left: -12px;
line-height: 30px;
width: 90%;
background-color: #686868;
text-align: center;
color:white;
}
.tab-right {
position: absolute;
float: left;
margin-left: -7px;
width: 20px;
height: 30px;
border-radius: 1px;
background-color: #686868;
transform: skew(20deg);
}

<ul class="tabs" role="tablist">
<div class="all-tab" data-tab="details">
<span class="tab-left"></span>
<span class="tab-centre"><li><a class="active" id="btn1" href="#">ALL</a></li></span>
<span class="tab-right"></span>
</div>
<div class="tab first-tab" data-tab="details">
<span class="tab-left"></span>
<span class="tab-centre"><li><a class="first" id="btn2" href="#">first</a></li></span>
<span class="tab-right"></span>
</div>
</ul>
&#13;
当我点击第一个标签时,它应该更改文本和整个标签的颜色,直到选中下一个标签。我尝试了不同的CSS组合,但没有用。有没有办法在div内部改变颜色?
答案 0 :(得分:0)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
a:focus{
background:red;
}
a:focus div{
height:20px;
background:red;
}
a:focus span{
color:yellow;
}
a:active{
background:red;
}
a{
background:blue;
}
</style>
</head>
<body>
<ul class="tabs" role="tablist">
<li>
<a href="#" class="active">
<div>
<span>first</span>
</div>
</a>
</li>
<li>
<a href="#">
<div>
<span>second</span>
</div>
</a>
</li>
</ul>
</body>
</html>