首页 技术 正文
技术 2022年11月12日
0 收藏 939 点赞 2,285 浏览 3515 个字

1.css3属性选择器

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>css3属性选择器</title>
<style type="text/css">
/* id包含div字符串*/ [id*=div] {
color: lime;
}
/*开始字符串为div*/ [id^=div] {
color: red;
}
/*结束字符串为div*/ [id$=div] {
color: blue;
}
</style>
</head><body>
<div>
<div id="div1">11</div>
<div id="2div2">22</div>
<div id="3div3">33</div>
<div id="44div">44</div>
<div id="wowo">55</div>
</div>
</body></html>

2.css3结构伪类选择器

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>css3结构伪类选择器</title>
<style type="text/css">
/* 第一行*/ body>p:first-line {
color: aqua;
}
/* 首字母*/ body>p:first-letter {
color: red;
}
/*元素前插入内容*/ li:before {
content: "--";
color: yellow;
}
/*元素后插入内容*/ li:after {
content: "++";
color: green;
}
/*根元素*/ :root {
background: darkgrey;
}
/*排除*/ div *:not(h1) {
background: green;
}
/*为空*/ .bb li:empty {
background: green;
}
/*业内跳转目标*/ :target {
background: orange;
}
</style>
</head><body>
<p>
我是第一行
<br> 我是第二行
</p>
<ul>
<li class="aa">1</li>
<li>2</li>
<li class="aa">3</li>
<li class="aa">4</li>
</ul>
<ul class="bb">
<li>1</li>
<li></li>
<li>3</li>
<li></li>
<li>5</li>
<li></li>
</ul>
<div>
<h1>111</h1>
<h2>222</h2>
<h3>333</h3>
</div>
<a href="#a1" rel="external nofollow" >111</a>
<a href="#a2" rel="external nofollow" >222</a>
<a href="#a3" rel="external nofollow" >333</a>
<div id="a1">a1</div>
<div id="a2">a2</div>
<div id="a3">a3</div>
</body></html>

3.css3选择器

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>css3选择器</title>
<style type="text/css">
/*第一个元素*/ li:first-child {
background-color: yellow;
}
/*最后一个元素*/ li:last-child {
background-color: blue;
}
/*上到下第几个*/ li:nth-child(2) {
background-color: #666;
}
/*下到上第几个*/ li:nth-last-child(2) {
background-color: #888;
}
/*基数*/ li:nth-child(odd) {
color: red;
}
/*偶数*/ li:nth-child(even) {
color: #999;
}
/*只算同类元素*/ .aa h3:nth-of-type(2),
.aa h4:nth-of-type(2) {
color: red;
}
/*样式循环*/ .bb li:nth-child(4n+1) {
background-color: #111;
} .bb li:nth-child(4n+2) {
background-color: #222;
} .bb li:nth-child(4n+3) {
background-color: #333;
} .bb li:nth-child(4n) {
background-color: #444;
}
/*只有一个元素*/ li:only-child {
background-color: green;
}
</style>
</head><body>
<ul>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>55</li>
<li>66</li>
<li>77</li>
<li>88</li>
</ul>
<div class="aa">
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
<h3>111</h3>
<h4>222</h4>
</div>
<div class="bb">
<ul>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
</ul>
</div>
<ul>
<li>11</li>
</ul>
</body></html>

4.UI元素状态伪类选择器

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>UI元素状态伪类选择器</title>
<style type="text/css">
/*hover鼠标在控件上*/ input[type="text"]:hover {
background-color: darkviolet;
}
/*focus获取焦点*/ input[type="text"]:focus {
background-color: aqua;
}
/*active鼠标按住*/ input[type="text"]:active {
background-color: #666;
}
/*checked已选择状态*/ input[type="checkbox"]:checked {
outline: 2px solid gold;
}
/*enabled可用*/ .aa input[type="text"]:enabled {
background: yellow;
}
/*disabled不可用*/ .aa input[type="text"]:disabled {
background: red;
cursor: pointer;
}
</style>
</head><body>
<input type="text" name="name">
<input type="text" name="age">
<input type="checkbox">111
<input type="checkbox">222
<input type="checkbox">333
<div class="aa">
<input type="text" name="name" id="t1">
<input type="text" name="age" id="t2" disabled>
</div>
</body></html>

5.通用兄弟选择器

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>通用兄弟选择器</title>
<style type="text/css">
/*跟在div后面的p元素*/
div~p {
background: gold;
} </style>
</head><body>
<div>
<div>
<p>div的子元素p</p>
<p>div的子元素p</p>
</div>
<p>div相邻元素p</p>
<p>div相邻元素p</p>
<h4>----------</h4>
<div>
<p>div的子元素p</p>
</div>
<p>div相邻元素p</p>
<p>div相邻元素p</p>
</div>
<p>div相邻元素p</p>
<p>div相邻元素p</p>
</body></html>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,964
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781