CSS: hover选择器控制子元素的出现和隐藏

使用方法:.父元素:hover .子元素(hover和子元素之间需要一个空格),如:
.a:hover .b 

演示效果:


代码:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            
        
                   .alarm:hover .divright {
             display: block;
            }
        
            .alarm {
                position: relative;
                width: 60px;
                height: 60px;
                margin: 60px;
            }
            
            .alarm img {
                width: 60px;
                height: 60px;
            }
            
            .divright {
                position: absolute;
                color: white;
                font-size: 17px;
                background-color: red;
                width: 23px;
                height: 25px;
                line-height: 25px;
                left: 80%;
                top: -12px;
                text-align: center;
                -webkit-border-radius: 24px;
                border-radius: 24px;
                display: none;
            }
        </style>
    </head>

    <body>
        <div class="alarm">
            <img src="img/1.png" />
            <div class="divright">
                3
            </div>
        </div>
    </body>
</html>
 
posted @ 2021-08-18 15:11  专注网站建设和推广  阅读(1162)  评论(0编辑  收藏  举报