The display and hiding of elements-HTML+CSS study notes 21

Similar to website ads, when we click to close it disappears, but we refresh the page again, it will reappear!
Essence: Let an element be hidden or displayed on the page.

display show hide

display: none ;隐藏对象 
display:block ;除了转换为块级元素之外,同时还有显示元素的意思 

After the display hides the element, it no longer occupies the original position.
The latter is widely used, and it can do a lot of webpage special effects with JS.

Insert picture description here
Insert picture description here

visibility show hide

visibility:visible ;  元素可视 
visibility:hidden;  元素隐藏 

After visibility hides the element, it continues to occupy the original position.

overflow overflow display hide

Insert picture description here
If there is a positioning box, please use overflow: hidden carefully because it will hide the extra part.
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Tudou Mouse passing display mask

When the mouse passes: When the
Insert picture description here
mouse does not pass:
Insert picture description here
Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box {
     
     
        position: relative;
        width: 444px;
        height: 320px;
        background-color: pink;
        margin: 30px auto;
    }
    .box img {
     
     
        width: 100%;
        height: 100%;
    }
    .mask {
     
     
        display: none;
        position: absolute;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, .4) url(btn.png) no-repeat center;
    }
    /* 不能这样写,因为mask被隐藏了不占位置(自己的猜测 但是用visible好像也不行啊)
    .mask:hover {
        display: block;
    } */

     /* 当我们鼠标经过了这个盒子,就让里面遮罩层显示出来 */
    .box:hover .mask {
     
     
        display: block;
    }
    
</style>
<body>
    <div class="box">
        <div class="mask"></div>
        <img src="pic.jpg" alt="图片">
    </div>
</body>
</html>

Guess you like

Origin blog.csdn.net/weixin_45019830/article/details/107885607
Recommended