使用 CSS 控制元素的可见性

cssweb developmentfront end technology更新于 2024/11/29 2:52:17

CSS Display 属性用于控制网页上元素的可见性。此处显示了它的部分值 −

将元素显示为内联级弹性容器

Sr.No属性值 &说明
1inline
将元素显示为内联元素。
2block
将元素显示为块元素。
3contents
使容器消失,使元素的子元素成为 DOM 中的下一级子元素
4flex
将元素显示为块级弹性容器
5grid
将元素显示为块级网格容器
6inline-block
将元素显示为内联级块容器。
7inline-flex
将元素显示为内联级弹性容器
8inline-grid
将元素显示为内联级网格容器
9inline-table
元素显示为内联级表格

示例

现在让我们看一个实现 CSS display 属性的示例 −

<!DOCTYPE html>
<html>
<head>
<style>
span {
   background-color: orange;
   color: white;
}
p.demo {
   display: none;
}
span.demo1 {
   display: inline;
}
</style>
</head>
<body>
<h1>Match Details</h1>
<div>
Match will begin at <p class="demo">9AM</p> 10AM on 20th December.
</div>
<div>
Match will end at <span class="demo1">5PM</span> on 20th December.
</div>
</body>
</html>

输出

示例

现在让我们看另一个例子 −

<!DOCTYPE html>
<html>
<head>
<style>
p {
   background-color: orange;
   color: white;
}
p.demo1 {
   display: block;
}
p.demo2 {
   display: inline-block;
}
</style>
</head>
<body>
<h1>Match Details</h1>
<div>
Match will begin at <p class="demo1">10AM</p> on 19th Decemenber, 2019.
</div>
<div>
Match will end at <p class="demo2">5PM</p> on 19th Decemenber, 2019.
</div>
</body>
</html>

输出


相关文章


有用资源