对:target的理解(纯CSS实现图片选项卡)

---恢复内容开始---

:target是CSS3添加的伪类元素

用法: el.target{

                  /*表示的是锚点的变化*/

     background:yellow;

           }

   el:表示被a标签的href属性绑定的锚点

:锚点的用法:a的href=锚点的id值

下面是我做的例子,点击圆点,显示图片,类似于选项卡效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        img{
            width: 500px;
        }
        a{
            display:inline-block;
            width: 25px;
            height:25px;
            border-radius: 50%;
            background: orange;
            position: relative;
            top:236px;
            left: 401px;
            z-index: 2;
            line-height: 25px;
            text-align: center;
            text-decoration: none;
        }
        i{
            display: block;
            width: 500px;
            height: 281.25px;
            position: absolute;
            top:0;
        }
     /*点击哪个a标签显示哪张图片*/ #i4{ background: url('a.png'); background-size: cover; } #i4:target{ background:url('a.png'); background-size: cover; }#i5:target{ background:url('b.png'); background-size: cover; }#i6:target{ background:url('c.png'); background-size: cover; }
</style> </head> <body> <a id="i1" href="#i4">1</a> <a id="i2" href="#i5">2</a> <a id="i3" href="#i6">3</a> <i id="i4"></i> <i id="i5"></i> <i id="i6"></i> </body> </html>

效果图

 

自己的理解,如果有错误望指出

 

posted @ 2018-09-19 21:30  学会谦卑博古  阅读(429)  评论(0编辑  收藏  举报