一个行内元素 (opens new window)只占据它对应标签的边框所包含的空间。
This span is an inline element; its background has been colored to display both the beginning and end of the inline element's influence
<html>
<body>
<div class="demo0">
<p>This <span>span</span> is an inline element; its background has been colored to display both the beginning and end of the inline element's influence</p>
</div>
</body>
</html>
<script>
</script>
<style>
.demo0 span {
background-color: #8abb55;
}
</style>
b
, big
, i
, small
, tt
abbr
, acronym
, cite
, code
, dfn
, em
, kbd
, strong
, samp
, var
a
, bdo
, br
, img
, map
, object
, q
, script
, span
, sub
, sup
button
, input
, label
, select
, textarea
水平居中
垂直居中
水平垂直居中
<html>
<body>
<div class="demo1">
<div>
<span>水平居中</span>
</div>
<div>
<span>垂直居中</span>
</div>
<div>
<span>水平垂直居中</span>
</div>
</div>
</body>
</html>
<script>
</script>
<style>
.demo1 {
display: flex;
flex-direction: column;
}
.demo1 div {
border: 1px solid lightgray;
}
.demo1 span {
background-color: #8abb55;
}
.demo1 div:nth-child(1) {
text-align: center;
}
.demo1 div:nth-child(2) {
height: 100px;
line-height: 100px;
}
.demo1 div:nth-child(3) {
height: 100px;
line-height: 100px;
text-align: center;
}
</style>
块级元素 (opens new window)占据其父元素(容器)的整个水平空间,垂直空间等于其内容高度,因此创建了一个“块”。
块级元素只能出现在 <body>
元素内。
This paragraph is a block-level element; its background has been colored to display the paragraph's parent element.
<html>
<body>
<div class="demo3">
<p>This paragraph is a block-level element; its background has been colored to display the paragraph's parent element.</p>
</div>
</body>
</html>
<script>
</script>
<style>
.demo3 p {
background-color: #8abb55;
}
</style>
<address>
<article>
<aside>
<blockquote>
<dd>
<div>
<dl>
<fieldset>
<figcaption>
<figure>
<footer>
<form>
<h1>
、<h2>
、<h3>
、<h4>
、<h5>
、<h6>
<header>
<hgroup>
<hr>
<ol>
<p>
<pre>
<section>
<table>
<ul>
水平居中
水平垂直居中
<html>
<body>
<div class="demo2">
<div>
<p>水平居中</p>
</div>
<div>
<p>水平垂直居中</p>
</div>
</div>
</body>
</html>
<script>
</script>
<style>
.demo2 {
display: flex;
flex-direction: column;
}
.demo2 div {
border: 1px solid lightgray;
}
.demo2 p {
width: 40%;
background-color: #8abb55;
}
.demo2 div:nth-child(1) p {
margin: 0 auto;
}
.demo2 div:nth-child(2) {
height: 100px;
display: flex;
justify-content: center;
align-items: center;
}
</style>
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有