今天(昨天)又发现一个知识盲区

css3的:target标签,之前学习的时候就是一眼扫过,说是认识了,但其实也就记了三分钟,合上书就全忘光了。

直到昨天,遇到一个有意思的题目,用css3新特性做一个类似tab标签的小效果,才让我又重新认识了  :target  选择器

w3c上对于target选择器的解释是:

试一下他的效果就能对target的作用明白了:http://www.w3school.com.cn/tiy/t.asp?f=css_sel_target

原理: 也就是给一个元素A设定id,另一个元素B指定跳转到这个id,然后就向 a:hover 那样,在css中设定 “元素:target”并改变样式,那么点击B元素,就会根据你的设定改变A的样式。

以下就是我根据原理做出来的一个样式

很明显,就是一个tab切换效果,css制作。

代码如下:

html

     <div class="swiper-box">
<div class="swiper-cont">
<div class="swiper1" id="swiper1">
</div>
<div class="swiper2" id="swiper2">
</div>
<div class="swiper3" id="swiper3">
</div>
</div>
<div class="swiper-num">
<a href="#swiper1">1</a>
<a href="#swiper2">2</a>
<a href="#swiper3">3</a>
</div>
</div>

css

 .swiper-box{
position: relative;
width: 500px;
height: 300px;
margin: 20px auto;
background: #f1f1f1;
}
.swiper-cont div,.swiper1,.swiper2,.swiper3{
width: 0%;
height: 300px;
position: absolute;
top:;
left:;
-webkit-transition: width .5s linear;
-moz-transition: width .5s linear;
-ms-transition: width .5s linear;
-o-transition: width .5s linear;
transition: width .5s linear;
}
.swiper1{
background: -webkit-linear-gradient(bottom, #fba555, #ffed6c 75%);
background: -moz-linear-gradient(bottom, #fba555, #ffed6c 75%);
background: -ms-linear-gradient(bottom, #fba555, #ffed6c 75%);
background: -o-linear-gradient(bottom, #fba555, #ffed6c 75%);
background: linear-gradient(to top, #fba555, #ffed6c 75%);
}
.swiper2{
background: -webkit-linear-gradient(right, #55d5fb, #fd74a7 75%);
background: -moz-linear-gradient(right, #55d5fb, #fd74a7 75%);
background: -ms-linear-gradient(right, #55d5fb, #fd74a7 75%);
background: -o-linear-gradient(right, #55d5fb, #fd74a7 75%);
background: linear-gradient(to left, #55d5fb, #fd74a7 75%);
}
.swiper3{
background: -webkit-linear-gradient(bottom right, #55fb69, #6cfff1 75%);
background: -moz-linear-gradient(bottom right, #55fb69, #6cfff1 75%);
background: -ms-linear-gradient(bottom right, #55fb69, #6cfff1 75%);
background: -o-linear-gradient(bottom right, #55fb69, #6cfff1 75%);
background: linear-gradient(to top left, #55fb69, #6cfff1 75%);
}
.swiper-num{
position: absolute;
bottom:;
right:;
display: inline-block;
z-index:;
}
.swiper-num a{
display: inline-block;
margin-left: 10px;
padding: 10px 20px;
color: #333;
font-size: 14px;
text-decoration: none;
font-weight: bold;
background: rgba(255,255,255,.45);
}
.swiper-num a:hover,.swiper-num a:active{
color: red;
cursor: pointer;
background: rgba(255,255,255,.95);
}
.swiper-box :target{
width: 100%;
-webkit-transition: width .5s linear;
-moz-transition: width .5s linear;
-ms-transition: width .5s linear;
-o-transition: width .5s linear;
transition: width .5s linear;
}
.in-cont{
height: 60px;
}

核心关键点我觉得除了第63行的:target选择器以外,还有就是,所谓的指定target目标id的元素,也就是使用了(href=“#xxx”)属性的元素,一定要是a链接,(比如我div.swiper-num里边的a链接就是zhongdian!!!)

曾经我用span,然后捣鼓到了晚上八点最后明白需要a后才下班。。。

难道href是a的御用吗

更多的技巧这篇文章做的很仔细:http://www.css88.com/archives/6256

css3-巧用选择器 “:target”的更多相关文章

  1. css3巧用选择器配合伪元素

    一 . 前言 有时我们在写底部导航栏时,会有很多超链接,每个链接间用“|”分割,如下图: 可能刚入门的朋友会想到这样完成,再单独设置span的样式, 今天主要介绍怎么样用css3简单快速的完成这个效果 ...

  2. 极客技术专题【008期】:CSS3核心技术:选择器

    日期:2013-8-19  来源:GBin1.com 技术专题介绍 技术专题:CSS3核心技术:选择器 专题演讲稿:CSS3选择器 分享人:知名前端技术博客 - w3cplus.com 博主 - 大漠 ...

  3. jQ not()选择器 与 css3 :not( selector )选择器

    1.jQ  not() 2.css3 not  w3c在线演示地址  http://www.w3school.com.cn/tiy/t.asp?f=css_sel_not 总结: 注意两者还是有区别的 ...

  4. css3的nth-child选择器的具体探讨

    css3的nth-child选择器的具体探讨 前言 在十年前開始的div+css布局兴起之时,我就開始了CSS的学习和实践.在当年,对于CSS选择器,基本上是没有什么选择性的,仅仅有ID选择器,CLA ...

  5. CSS3 伪类选择器 nth-child() 的用法

    伪类选择器 nth-child() 在IE6-8和FF3.0-浏览器不支持,CSS3中nth-of-type(n)(比如nth-of-type(1))这个特殊的类选择符可以样式更加个性的标题和段落等, ...

  6. CSS3的属性选择器

    CSS3中新增了许多选择器,今天零度给大家说说CSS3的属性选择器. 与CSS2相比,CSS3新增了3种属性选择器:[attr^=value].[attr$=value].[attr*=value]: ...

  7. IT兄弟连 HTML5教程 CSS3揭秘 CSS选择器1

    要使用CSS对HTML页面中的元素实现一对一.一对多或者多对一的控制,就需要用到CSS选择器.选择器是CSS3中一个重要的内容,使用它可以大幅度地提高开发人员书写或修改样式表的效率.在大型网站中,样式 ...

  8. CSS3的nth-child() 选择器

    CSS3的nth-child() 选择器,表格奇偶行变色 nth-child() 应用背景 CSS3的nth-child() 选择器,我之前很少用,在做表格偶数行变色的时候,我通常在绑定的时候,做一个 ...

  9. CSS3 nth-of-type(n)选择器 last-of-type选择器 nth-last-of-type(n)选择器 CSS3 only-child选择器 only-of-type选择器

    CSS3 nth-of-type(n)选择器 “:nth-of-type(n)”选择器和“:nth-child(n)”选择器非常类似,不同的是它只计算父元素中指定的某种类型的子元素.当某个元素中的子元 ...

  10. JQ表单选择器和CSS3表单选择器

    JQ表单选择器和CSS3表单选择器 JQ表单选择器 为了使用户能够更加灵活地操作表单,jQuery中加入了表单选择器,利用这个选择器能极其方便的获取到表单的某个或者某类型的元素.表单选择器的介绍如图: ...

随机推荐

  1. SpringMVC 利用AbstractRoutingDataSource实现动态数据源切换

    SpringMVC 利用AbstractRoutingDataSource实现动态数据源切换 本文转载至:http://exceptioneye.iteye.com/blog/1698064 Spri ...

  2. JavaScript(一):JavaScript简介

    一.什么是JavaScript JavaScript是一种具有面向对象能力的.解释性的程序设计语言.更具体一点,它是基于对象和事件驱动并具有相对安全性的客户端脚本语言.因为他不需要在一个语言环境下运行 ...

  3. jQuery方法笔记

    .clone() $(selector).clone(includeEvents) $(this).clone(true) //boolean值,true/false分别对饮是否复制元素的所有事件处理

  4. linux ffmpeg编译配置安装详解

    http://www.111cn.net/sys/linux/53039.htm ffmpeg是一开源的可跨平台使用的一个图形处理插件,这可以进行录制.转换以及流化音视频,同时可以对视频进行截图,下面 ...

  5. LINUX下CPU Load Average的一点研究

    背景: 公司的某个系统工作在基于Linux的Cent OS下,一个host下同时连接了许多client, 最近某台Host总是显示CPU Load Average过高,我们单纯的以为是CPU的占用过高 ...

  6. 转载:【原译】Erlang列表处理(Efficiency Guide)

    转自:http://www.cnblogs.com/futuredo/archive/2012/10/22/2734186.html List handling 1  Creating a list ...

  7. $.ajax的一般用法

    $.post.$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax() 一.$.ajax的一般格式 $.ajax({ type: 'POST', url: url , ...

  8. HBase复制

    HBase复制是一种在不同HBase部署中复制数据的方法.它能够作为一种故障恢复的方法,并提供HBase层次的高可用性.在实际应用中,比如.能够将数据从一个面向页面的集群拷贝到一个MapReduce集 ...

  9. centos7 修改主机名的方法(在centos7有效)

    参考链接:http://www.centoscn.com/CentOS/config/2014/1031/4039.html 在CentOS或RHEL中,有三种定义的主机名:a.静态的(static) ...

  10. LR通用的性能分析流程

    Step1:从分析Summary的事务执行情况入手Summary主要是判定事务的响应时间与执行情况是否合理.如果发现问题,则需要做进一步分析.通常情况下,如果事务执行情况失败或响应时间过长等,都需要做 ...