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

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. 非分离线程未使用join函数例子:

    //非分离线程未使用join函数例子: #include<stdlib.h> #include<pthread.h> #include<stdio.h> #incl ...

  2. Smack 广播

    格式 Message message = new Message("all@broadcast.192.168.1.253"); 使用openfire的广播功能首先需要在插件的页面 ...

  3. 一站式学习Wireshark(十):应用Wireshark显示过滤器分析特定数据流(下)

    介绍 掌握显示过滤器对于网络分析者来说是一项必备的技能.这是一项大海捞针的技巧.学会构建,编辑,保存关键的显示过滤器能够节省数小时的时间. 与捕捉过滤器使用的BPF语法不同,显示过滤器使用的是Wire ...

  4. mysql 修改用户权限,允许远程连接数据库

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'admin123' WITH GRANT OPTION; flush privileg ...

  5. PHP框架之ThinkPHP项目CMS内容管理系统源码及开发手册视频

    http://download.csdn.net/download/duguqing/4203042

  6. 试读《基于MVC的JavaScript Web富应用开发》— 不一样的JavaScript

    前言 <基于MVC的JavaScript Web富应用开发>是ItEye在7月份发起试读的书.下载了试读的章节,发现只有全本的开始到第二章,第一章很简洁明了地讲述了JavaScript的历 ...

  7. thinkphp openfire 添加用户 骨架

    public function addadd(){ header("Content-Type:text/html; charset=utf-8"); $user=$_POST['n ...

  8. 关于Cocos2d-x中文乱码问题的解决

    方法一: 1.首先,复制下面的代码,创建一个icov,h的头文件,并放在项目目录下 #include "stdlib.h"#include "string.h" ...

  9. e591. Drawing Simple Text

    See also e575 The Quintessential Drawing Program. public void paint(Graphics g) { // Set the desired ...

  10. Eclipse/MyEclipse全屏插件

    此插件可以让Eclipse/MyEclipse的界面全屏,隐藏菜单栏和状态栏! MyEclipse 2014/2015中亲测有效! 插件下载: http://files.cnblogs.com/got ...