在网站上经常会有一些需要一定操作才会显示或隐藏的元素,这时会用到元素的隐藏与显示。主要通过以下三种属性实现。

1、display :none|block |inline |inline-block

display常用以上四个属性值,none 是元素隐藏,且不占有位置。block  除了转换为块级元素之外,同时还有显示元素的意思。inline 和inline-block 分别是显示为行内元素和行内块元素。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            margin: 0;
        }
        
        div:first-child {
            background-color: aqua;
        }
        
        div:nth-child(2) {
            background-color: red;
            display: none;
        }
        
        div:last-child {
            background-color: pink;
        }
    </style>
</head>

<body>
    <div></div>
    <div></div>
    <div></div>
</body>

</html>
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
猜你喜欢
  • 2021-12-18
  • 2021-12-18
  • 2021-04-17
  • 2021-04-12
  • 2021-07-28
相关资源
相似解决方案