作者:yuhao | 来源:互联网 | 2022-11-20 21:44
我有一个div
包含两个label
元素.每个人都label
应该站在一边div
.由于标签是内联元素,我已经尝试过display: block
并且还有display: inline-block
边距生效,但结果不是预期的结果.
div {
color: #ffffff;
background-color: #3f3f3f;
}
label:nth-of-type(1) {
margin-left: 5px;
}
label:nth-of-type(2) {
display: block;
margin-right: 5px;
margin-left: auto;
}
正如您在代码执行中看到的那样,第二个标签不尊重边距,而是显示在第一个标签下面.
1> 小智..:
标签必须有宽度并显示:block以使用margin auto.
今天,使用flexbox更灵活.
div {
color: #ffffff;
background-color: #3f3f3f;
display:flex;
flex-flow: row nowrap;
justify-content: space-between;
}
label:nth-of-type(1) {
margin-left: 5px;
}
label:nth-of-type(2) {
margin-right: 5px;
}