使用 CSS 控制元素的可见性
cssweb developmentfront end technology更新于 2024/11/29 2:52:17
CSS Display 属性用于控制网页上元素的可见性。此处显示了它的部分值 −
将元素显示为内联级弹性容器
| Sr.No | 属性值 &说明 |
|---|---|
| 1 | inline 将元素显示为内联元素。 |
| 2 | block 将元素显示为块元素。 |
| 3 | contents 使容器消失,使元素的子元素成为 DOM 中的下一级子元素 |
| 4 | flex 将元素显示为块级弹性容器 |
| 5 | grid 将元素显示为块级网格容器 |
| 6 | inline-block 将元素显示为内联级块容器。 |
| 7 | inline-flex 将元素显示为内联级弹性容器 |
| 8 | inline-grid 将元素显示为内联级网格容器 |
| 9 | inline-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>
输出

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

