【发布时间】:2019-04-04 17:20:39
【问题描述】:
如何将水平对齐应用于<label> 元素?如果我这样做<label><p>3</p></label> 一切正常。我不明白为什么<p> 元素有自动边距(居中),而<label> 没有。
html
body {
background: #2b2b2b;
font-size: 36px;
font-family: Helvetica neue, roboto;
color: white;
}
.main {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 75%;
margin: 0 auto;
background: black;
}
.common {
width: 45%
}
#div1 {
background: purple;
text-align: right;
}
#div2 {
background: orange;
}
#div3 {
background: olive;
text-align: right;
}
#div4 {
background: gray;
}
label {
}
<div class="main">
<div id="div1" class="common">1</div>
<div id="div2" class="common">2</div>
<div id="div3" class="common"><label for="name-label">3</label></div>
<div id="div4" class="common"><p>4</p></div>
</div>
【问题讨论】:
-
请复制问题中的代码,请勿在图片中发布代码
-
请不要外链和截图。使用 StackOverflow sn-p。
-
p 有默认边距,不是自动边距
-
外部链接接缝不起作用????
-
您要水平对齐还是垂直对齐?因为你说的是水平的,但从你的代码看来你正在尝试垂直
标签: html css text-align