根据属性值来查找元素的方式:
li[style] {
text-decoration: underline;
}
li[class=red] {
font-size: 30px;
}
li[class*=red] {
background-color: cyan;
}
li[class^=red] {
border: 1px solid black;
}
li[class$=red] {
padding-top: 10px;
}
以某元素相对于其父元素或兄弟元素的位置来获取元素的结构伪类。
li:first-child {
color: red;
}
li:last-child {
color: skyblue;
}
li:first-of-type {
color: red;
}
li:last-of-type {
background-color: pink;
}
li:nth-child(3) {
text-decoration: underline;
}
/*even:偶数,odd奇数*/
/*li:nth-child(even) {
background-color: green;
}
li:nth-child(odd) {
background-color: orange;
}*/
li:nth-last-of-type(even) {
background-color: green;
}
li:nth-last-of-type(odd) {
background-color: orange;
}
/*取值范围是0~子元素长度,小于1的值无效,如下表示前5个和后5个:*/
li:nth-of-type(-n+5) {
font-size: 30px;
}
li:nth-last-of-type(-n+5) {
text-decoration: underline;
}
li:empty {
background-color: yellow;
}
.one ~ p {
color: cyan;
}
.two + p {
background-color: red;
}
E:target——为锚点目标元素添加样式,当目标元素触发为当前锚链接时调用此伪类样式:
h3:target {
color: red;
}
形如E::before、E::after的伪元素:
注意:
div.blue:nth-of-type(2):before {
content: "";
width: 20px;
height: 20px;
position: absolute;
border-radius: 10px;
background-color: #cae8ca;
left: -10px;
top: -10px;
}
div.blue:nth-of-type(2):after {
content: "";
width: 20px;
height: 20px;
position: absolute;
border-radius: 10px;
background-color: #cae8ca;
left: -10px;
bottom: -10px;
}
/*获取第一个字符,实现首字下沉效果*/
p.title::first-letter {
font-size: 40px;
/*文本环绕*/
float: left;
}
p.content::first-letter {
color: red;
}
/*获取第一行内容,如果设置了first-letter*/
p.content::first-line {
text-decoration: underline;
}
p.content::selection {
background-color: #cccccc;
}
li.color1 {
color: red;
}
li.color2 {
color: #ff0000;
background-color: #00ffff6e;
}
li.color3 {
color: rgb(255, 0, 0);
background-color: rgba(0, 255, 255, 0.5);
}
li.color4 {
color: hsl(0, 100%, 50%);
background-color: hsla(180, 100%, 50%, 0.5);
}
透明度说明:
文本阴影如下表示:
text-shadow: x轴偏移 y轴偏移 模糊半径 颜色, x轴偏移 y轴偏移 模糊半径 颜色……
或者如下表示:
text-shadow:颜色 x轴偏移 y轴偏移 模糊半径 , 颜色 x轴偏移 y轴偏移 模糊半径……
div.shadow1 {
color: white;
text-shadow: -1px -1px 2px red;
}
div.shadow2 {
color: white;
text-shadow: 0px 0px 10px white;
}
div.shadow3 {
color: black;
text-shadow: 0px 0px 5px white, 0px 0px 10px red;
}
div.shadow4 {
color: black;
text-shadow: 0px 1px 1px white;
}
div.shadow5 {
color: white;
text-shadow: -1px -1px 0px #eeeeee, -2px -2px 0px #cccccc, -3px -3px 0px #bbbbbb, -4px -4px 0px #aaaaaa;
}
div.shadow6 {
color: white;
text-shadow: 0px -1px 0px #eeeeee, 0px -2px 0px #cccccc, 0px -3px 0px #bbbbbb, 0px -4px 0px #aaaaaa;
}
div.shadow7 {
color: transparent;
text-shadow: 0px 0px 5px hsl(20, 100%, 50%);
}
默认情况下,css设置盒子的宽高仅仅是内容的宽高,真正的宽高会加上一些其他内容:
css3中box-sizing来指定盒模型content-box、border-box改变计算盒子大小的方式:
盒模型对比:
div.div1 {
width: 100px;
height: 100px;
background-color: red;
float: left;
padding-right: 10px;
border-right: 10px solid pink;
}
div.div2 {
width: 100px;
height: 100px;
background-color: green;
float: left;
}
div.div3 {
width: 100px;
height: 100px;
background-color: blue;
float: left;
padding-right: 10px;
border-right: 10px solid yellow;
box-sizing: border-box;
}
div.div4 {
width: 100px;
height: 100px;
background-color: cyan;
float: left;
}
盒模型案例,鼠标放上去加一个边框:
div.item {
width: 30%;
height: 100px;
background-color: red;
display: inline-block;
overflow: hidden;
margin-left: 2.5%;
box-sizing: border-box;
}
/*鼠标往上移的时候触发*/
div.item:hover {
border: 5px cyan solid;
}
border-radius定义样式相同的角,也能为每个角分别定义:
div.div1 {
border-radius: 10px;
}
div.div2 {
border-radius: 10px 20px 30px 40px;
}
div.div3 {
border-radius: 10px 20px;
}
div.div4 {
border-radius: 10px 20px 30px;
}
div.div5 {
border-radius: 10px/20px;
}
div.div6 {
border-radius: 10px 20px 30px 40px/50px 60px 70px 80px;
}
除了上述设置4个角外,还可以为每个角单独创建圆角:
div.div7 {
border-top-left-radius: 10px;
}
div.div8 {
border-top-right-radius: 10px;
}
div.div9 {
border-bottom-left-radius: 10px;
}
div.div10 {
border-bottom-right-radius: 10px;
}
div.div11 {
border-bottom-right-radius: 10px 20px;
}
绘制安卓机器人,主要是对伪元素、边框圆角的运用:
Title
机器人案例