伪元素:target
:target 伪类选择器
|
1
2
3
4
5
6
|
<ul class='nav'>
<li>列表1</li>
<li>列表2</li>
</ul>
<div>列表1内容:123456</div>
<div>列表2内容:abcdefgkijkl</div>
|
|
1
2
3
4
5
6
|
<ul class='nav'>
<li><a href="#content1">列表1</a></li>
<li><a href="#content2">列表2</a></li>
</ul>
<div id="content1">列表1内容:123456</div>
<div id="content2">列表2内容:abcdefgkijkl</div>
|
|
1
2
3
4
5
6
7
8
9
|
#content1,
#content2{
display:none;
}
#content1:target,
#content2:target{
display:block;
}
|
|
1
2
3
4
5
6
|
<div id="content1">列表1内容:123456</div>
<div id="content2">列表2内容:abcdefgkijkl</div>
<ul class='nav'>
<li><a href="#content1">列表1</a></li>
<li><a href="#content2">列表2</a></li>
</ul>
|
E~F{ cssRules } ,CSS3 兄弟选择符(E~F) ,选择 E 元素后面的所有兄弟元素 F。注意这里,最重要的一句话是 E~F 只能选择 E 元素 之后 的 F 元素,所以顺序就显得很重要了。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#content1:target ~ .nav li{
// 改变li元素的背景色和字体颜色
&:first-child{
background:#ff7300;
color:#fff;
}
}
#content2:target ~ .nav li{
// 改变li元素的背景色和字体颜色
&:last-child{
background:#ff7300;
color:#fff;
}
}
|

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.container {
position: relative;
width: 400px;
margin: 50px auto;
box-sizing: border-box;
}
.nav {
position: relative;
overflow: hidden;
list-style: none;
padding: 0;
margin: 0;
}
ul li{
list-style: none;
}
li {
width: 50%;
float: left;
text-align: center;
background: #ddd;
}
li a {
display: block;
line-height: 36px;
font-size: 18px;
cursor: pointer;
text-decoration: none;
color: #000;
}
#content1, #content2 {
position: absolute;
overflow: hidden;
top: 36px;
height: 100px;
border: 1px solid #999;
box-sizing: border-box;
}
#content1, #content2 {
display: none;
width: 100%;
background: #fff;
}
#content1:target, #content2:target {
display: block;
}
#content1.active {
display: block;
}
.active ~ .nav li:first-child {
background: #ff7300;
color: #fff;
}
#content1:target ~ .nav li {
background: #ddd;
color: #000;
}
#content1:target ~ .nav li:first-child {
background: #ff7300;
color: #fff;
}
#content2:target ~ .nav li {
background: #ddd;
color: #000;
}
#content2:target ~ .nav li:last-child {
background: #ff7300;
color: #fff;
}
</style>
</head>
<body>
<div class="container">
<div id="content1" class="active">列表1内容:123456</div>
<div id="content2">列表2内容:abcdefgkijkl</div>
<ul class='nav'>
<li class="active"><a href="#content1">列表1</a></li>
<li><a href="#content2">列表2</a></li>
</ul>
</div> </body>
</html>
法二:<input type="radio"> && <label for="">
|
1
2
3
4
5
|
<input class="nav1" type="radio">
<ul class='nav'>
<li>列表1</li>
</ul>
|
|
1
2
3
|
.nav1:checked ~ .nav li {
// 进行样式操作
}
|
同样用到了兄弟选择符 ~
|
1
2
3
4
5
|
<input class="nav1" id="li1" type="radio">
<ul class='nav'>
<li><label for="li1">列表1</label></li>
</ul>
|
label 标签中的 for 定义:for 属性规定 label 与哪个表单元素绑定。
|
1
2
3
|
input{
display:none;
}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<div class="container">
<input class="nav1" id="li1" type="radio" name="nav">
<input class="nav2" id="li2" type="radio" name="nav">
<ul class='nav'>
<li class='active'><label for="li1">列表1</label></li>
<li><label for="li2">列表2</label></li>
</ul>
<div class="content">
<div class="content1">列表1内容:123456</div>
<div class="content1">列表2内容:abcdefgkijkl</div>
</div>
</div>
|

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.container {
position: relative;
width: 400px;
margin: 50px auto;
}
input {
display: none;
}
.nav {
position: relative;
overflow: hidden;
}
* {
margin: 0;
padding: 0;
}
li {
float: left;
list-style: none;
text-align: center;
background: #ddd;
}
li label {
display: block;
width: 200px;
line-height: 36px;
font-size: 18px;
cursor: pointer;
}
.content {
position: relative;
overflow: hidden;
width: 400px;
height: 100px;
border: 1px solid #999;
box-sizing: border-box;
padding: 10px;
}
.content1,
.content2 {
display: none;
width: 100%;
height: 100%;
}
.nav1:checked ~ .nav li {
background: #ddd;
color: #000;
}
.nav1:checked ~ .nav li:first-child {
background: #ff7300;
color: #fff;
}
.nav2:checked ~ .nav li {
background: #ddd;
color: #000;
}
.nav2:checked ~ .nav li:last-child {
background: #ff7300;
color: #fff;
}
.nav1:checked ~ .content > div {
display: none;
}
.nav1:checked ~ .content > div:first-child {
display: block;
}
.nav2:checked ~ .content > div {
display: none;
}
.nav2:checked ~ .content > div:last-child {
display: block;
}
.active {
background: #ff7300;
color: #fff;
}
.default {
display: block;
}
</style>
</head>
<body>
<div class="container">
<input class="nav1" id="li1" type="radio" name="nav">
<input class="nav2" id="li2" type="radio" name="nav">
<ul class='nav'>
<li class='active'><label for="li1">列表1</label></li>
<li><label for="li2">列表2</label></li>
</ul>
<div class="content">
<div class="content1 default">列表1内容:123456</div>
<div class="content2">列表2内容:abcdefgkijkl</div>
</div>
</div>
</body>
</html>
伪元素:target的更多相关文章
- CSS笔记之伪类与伪元素
伪类分为两种:UI伪类 与 结构化伪类 UI伪类:a:link{} a:hover{} a:active{} a:visited{} input[type='text']:focus{} ...
- ::before和::after伪元素的用法
一.介绍 css3为了区分伪类和伪元素,伪元素采用双冒号写法. 常见伪类——:hover,:link,:active,:target,:not(),:focus. 常见伪元素——::first-let ...
- CSS伪类和伪元素
一.伪类 CSS伪类用于向某些选择器添加特殊的效果,在W3规范中,CSS伪类有如下几个: CSS2.1 :active:向被激活的元素添加样式(激活是指点击鼠标那一下) :focus:向拥有键盘输入焦 ...
- css伪类选择器及伪元素选择器
1.类选择器 在css中可以使用类选择器把相同的元素定义成不同的样式.比如: 结果如下: 标题背景未变 2.伪类选择器 类选择器和伪类选择器的区别在于,类选择器我们定义的,而伪类选择器是CSS中已经定 ...
- css3 -- 伪类与伪元素
伪类: 1.结构伪类 A:E : first-child{} E : nth-*(n){} E : first-*(even){} E : first-*(odd){} B:nth-child 是根 ...
- css伪元素选择器
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- CSS_03_04_CSS伪元素选择器
第01步:编写css代码:wei.css @charset "utf-8"; /* 伪元素选择器 :状态 效果顺序:L V H A */ a:link.lin_01{/*超链接,未 ...
- 使用css3伪元素制作时间轴并且实现鼠标选中高亮效果
利用css3来制作时间轴的知识要点:伪元素,以及如何在伪元素上添加锚伪类 1)::before 在元素之前添加内容. 2)::after 在元素之后添加内容. 提示:亦可写成 :before :aft ...
- CSS——伪元素与伪类
伪类与伪元素 伪类:在特殊性中占据0,0,1,0 :link 向未访问的链接添加特殊的样式.也就是说,链接所指的 URI 尚未出现在用户代理的历史中.这种状态与 :visited状态是互斥的. :vi ...
随机推荐
- 初学hadoop的个人历程
在学习hadoop之前,我就明确了要致力于大数据行业,成为优秀的大数据研发工程师的目标,有了大目标之后要分几步走,然后每一步不断细分,采用大事化小的方法去学习hadoop.下面开始叙述我是如何初 ...
- python之路 前段之html,css
一.HTML 超级文本标记语言是标准通用标记语言下的一个应用,也是一种规范,一种标准, 它通过标记符号来标记要显示的网页中的各个部分.网页文件本身是一种文本文件,通过在文本文件中添加标记符,可以告诉浏 ...
- 日志体系——loging
import loggingclass log: def __init__(self): # 文件的命名 self.logname=os.path.join(os.path.abspath(os.pa ...
- powerdesign初级入门教程
首先我们需要创建一个测试数据库,为了简单,我们在这个数据库中只创建一个Student表和一个Major表.其表结构和关系如下所示. 看看怎样用PowerDesigner快速的创建出这个数据库吧. 1. ...
- 2018-2019-2 20165114《网络对抗技术》Exp4 恶意代码分析
Exp4 恶意代码分析 目录 一.实验目标 (1)监控你自己系统的运行状态,看有没有可疑的程序在运行. (2)分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sys ...
- Git使用的常用命令
一.git工作流程 Workspace工作区:是当前工作目录,可以在此目录编辑文件 Index缓存区:add指令,保存文件的改动 Repository仓库:commit指令,将多次的文件改动最后提交 ...
- Spring Cloud 与 Spring boot - 转载
微服务是这样一个结构吗? 前端或二方 - > ng集群 -> zuul集群 -> eureka-server集群 -> service provider集群 (二方指其他业务部 ...
- Generate parentheses,生成括号对,递归,深度优先搜索。
问题描述:给n对括号,生成所有合理的括号对.比如n=2,(()),()() 算法思路:利用深度优先搜索的递归思想,对n进行深度优先搜索.边界条件是n==0:前面电话号组成字符串也是利用dfs. pub ...
- jdbc例子
public class ConnMysql { public static void main(String[] args) throws ClassNotFoundException, SQLEx ...
- Java中sleep()与wait()的区别
第一种解释: 功能差不多,都用来进行线程控制,他们最大本质的区别是:sleep()不释放同步锁,wait()释放同步缩. 还有用法的上的不同是:sleep(milliseconds)可以用 ...