赞
踩
- <style>
- div {
- margin: 100px auto;
- width: 200px;
- height: 200px;
- background-color: antiquewhite;
- }
- div:hover {
- /* 当鼠标在div元素上时颜色改变 */
- background-color: aqua;
- }
- </style>
鼠标按下时触发.抬起时还原
- <style>
- button {
- width: 100px;
- height: 40px;
- background-color: antiquewhite;
- }
- button:active {
- /* 当点击button元素上时颜色改变,鼠标抬起时,样式还原*/
- background-color: aqua;
- }
- </style>
一般用于输入框获取焦点时触发
- <style>
- inputn {
- width: 100px;
- height: 40px;
- }
-
- input:focus {
- /* 当输入框切换为输入状态时,输入框底色改变 */
- background-color: aqua;
- }
- </style>
- //CSS
- div:first-child {
- color: aqua;
- }
-
- //HTML
- <div>A</div>
- <div>B</div>
- <div>C</div>
- //CSS
- div:last-child {
- color: aqua;
- }
-
- //HTML
- <div>A</div>
- <div>B</div>
- <div>C</div>
- //CSS
- div:nth-child(2) {
- color: aqua;
- }
-
- //HTML
- <div>A</div>
- <div>B</div>
- <div>C</div>
- //CSS
- div {
- margin: 100px auto;
- width: 150px;
- height: 40px;
- text-align: center;
- line-height: 40px;
- background-color: orange;
- }
-
- div::before {
- //content是必须的,不然没有作用
- content: '2';
- }
-
- //HTML
- <div>=1+1</div>
- //CSS
- div {
- margin: 100px auto;
- width: 150px;
- height: 40px;
- text-align: center;
- line-height: 40px;
- background-color: orange;
- }
-
- div::after {
- //content是必须的,不然没有作用
- content: '2';
- }
-
- //HTML
- <div>1+1=</div>
- //CSS
- p::first-letter {
- font-size: 50px;
- }
-
- //HTML
- <p>
- abc <br>
- 123 <br>
- xyz
- </p>
伪类选择器和伪类元素比较常用的就在上面,还有一些不常用的,大家在学习中慢慢积累.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。