使用 CSS Display 属性

cssweb developmentfront end technology更新于 2024/11/5 20:28:17

CSS Display 属性用于设置元素在网页上的显示方式。它的一些值显示在这里 −

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

示例

现在让我们看一个例子实现 CSS 显示属性 −

<!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>

输出


相关文章


有用资源