CSS3 选项卡

CSS3选项卡小效果,以前都是用js写选项卡,发现利用CSS3的:target伪类也可以,简单粗暴

target伪类只在点击触发目标那一刻触发target伪类,所以把块隐藏掉,在点的时候让div展现成block。

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="demo.css">
</head>
<body>

<a href="#green">green</a>
<a href="#red">red</a>
<a href="#yellow">yellow</a>

<div id="wraper">
    <div class="items" id="green"></div>
    <div class="items" id="red"></div>
    <div class="items" id="yellow"></div>
</div>

</body>
</html>

CSS:

#wraper{
    height: 200px;
    overflow: hidden;
    width: 200px;
    border: 2px solid black;
}
.items{
    width: 200px;
    height: 200px;
    display: none;
}
#wraper .items:target{
    display: block;
}
.items:nth-child(1){
    background: green;
}
.items:nth-child(2){
    background: red;
}
.items:nth-last-child(1){
    background: yellow;
}

 

posted @ 2015-11-29 11:38  kiscall  阅读(298)  评论(0编辑  收藏  举报