css hover属性的用法(详解css中的hover怎么用)

今天详解css中的hover怎么用?hover属性用不同的书写方式,来改变不同关系的元素样式。1)元素:hover表示聚焦后改变自己2)元素:hover元素表示聚焦后改变其子元素3)元素:hov

今天详解css中的hover怎么用?hover属性用不同的书写方式,来改变不同关系的元素样式。

1)元素:hover 表示聚焦后改变自己

2)元素:hover 元素 表示聚焦后改变其子元素

3)元素:hover + 元素 表示聚焦后改变其指定的“亲兄弟”(条件是该兄弟元素与其相邻)元素

4)元素:hover ~ 元素 表示聚焦后改变其指定的兄弟元素,两个元素相不相邻都行。

示例: 

.first:hover {color: white;}/* 聚焦我改变自己 */.three:hover .three-son {font-size: 20px;}/* 聚焦我改变我的子元素 */.two:hover+.three {color: white;}/* 聚焦我改变我相邻的兄弟元素 */.first:hover~.four {font-weight: 900;color: palegreen;}/* 聚焦我改变不相邻的兄弟元素*/

效果图示:

css hover属性的用法(详解css中的hover怎么用)

css hover属性的用法完整代码如下:

<!DOCTYPE html><html> <head>    <meta charset="UTF-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</title>    <style>        .all{            background-color: orchid;            width: 200px;        }        .all :nth-child(-n+3){            margin-bottom: 10px;        }        .first {color: yellow;}        .two {color: red;}        .three {color: black;}        .three-son {color: black;}        .four {color: green;}                .first:hover {color: white;}/* 聚焦我改变自己 */        .three:hover .three-son {font-size: 20px;}/* 聚焦我改变我的子元素 */        .two:hover+.three {color: white;}/* 聚焦我改变我相邻的兄弟元素 */        .first:hover~.four {font-weight: 900;color: palegreen;}/* 聚焦我改变不相邻的兄弟元素 */    </style></head> <body>    <div>        改变本身,改变不相邻(~):        <div>我是黄字</div>        改变相邻(+):        <div>我是红字</div>        改变子元素:        <div>我是老黑            <div>我是小黑</div>        </div>        <div>我是绿字</div>    </div></body></html>
本站部分文章来自网络或用户投稿,如无特殊说明或标注,均为本站原创发布。涉及资源下载的,本站旨在共享仅供大家学习与参考,如您想商用请获取官网版权,如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
前端

css鼠标经过样式会动(两种方法实现鼠标经过样式改变)

2022-11-26 1:25:10

前端

前端line-height属性的用法(css文本属性line-height详解)

2022-11-26 1:25:14

搜索