CSS3伪类: target 是很特别属性中的一个.它是用来匹配页面(文档)的URI(用来表示页面资源的统一标识符)指向资源的内部的目标元素(anchor标志符指向的元素).这种URI以'#'结束,anchor标识符和目标元素的Id一致。因此简单点来讲就是浏览器
target伪类匹配以anchor标识符的值为id的目标元素.好比#number1,target就是用来匹配ID为number1的元素的。ide
如今在页面中,点击一个ID连接后,页面只会跳转到相应的位置,可是并不会有比较明显的UI标识,使用:target伪类能够像:hover等伪类同样对目标元素定义样式。spa
浏览器支持状况.net
IE9+, Chrome 3.0+, firefox, safirifirefox
如何使用呢?code
selector:target selector{ /*todo*/ }
如下经过一个实例来讲明blog
<div id="slidebox"> <div id="test1" class="test1" length="100"> <h4 desc="删除">我是一段描述文本</h4> <a id="folder" class="down" href="#">关闭</a> <a id="collapse" class="up" href="#slidebox">查看</a> <p> There is a section for descrption me. that introduct my experience and what my job for? There is a section for descrption me. that introduct my experience and what my job for? There is a section for descrption me. that introduct my experience and what my job for? </p> </div> </div>
配置伪类
.test1 p{ opacity: 0; max-height: 100px; transition: opacity .5s ease-in-out; } a{ position: absolute; top: 40px; background-color: #fff; } .up{ z-index: 3; } .down{ z-index: 2; } #slidebox:target .up{ z-index: 1; } #slidebox:target #test1 p{ opacity: 1; }
DEMO狂戳这里
扩展阅读: