【发布时间】:2018-11-27 03:54:04
【问题描述】:
我创建了一个带有文本和两个按钮的横幅。我使用 Inline-block 元素来对齐元素,因为我不想使用 flex。横幅上的左侧填充设置正确,但右侧不正确。我可以将横幅内容(#wrapper 元素)在屏幕上居中,以便左侧和右侧的填充等于 90 像素。你对这个问题有什么想法吗?这是我的代码,这是demo
#wrapper {
background-color: gray;
padding-left: 90px;
padding-right: 90px;
}
#wrapper:after {
content: "";
display: table;
clear: both;
}
#left {
padding-top: 33px;
padding-bottom: 33px;
width: 65%;
display: inline-block;
height: 80px;
line-height: 44px;
float: left;
}
#right {
padding-top: 45px;
padding-bottom: 45px;
display: inline-block;
float: left;
}
#button1 {
height: 70px;
width: 70px;
margin-right: 20px;
background-color: red;
display: inline-block;
}
#button2 {
height: 70px;
width: 70px;
background-color: green;
display: inline-block;
}
<div id="wrapper">
<div id="left">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard.
</div>
<div id="right">
<div id="button1">more</div>
<div id="button2">ok</div>
</div>
</div>
【问题讨论】:
-
不确定您是否需要另一个问题,这似乎与此相同:stackoverflow.com/questions/53478572/… .. 您可以编辑旧的或删除它,两者都有相同的目的
-
附带说明,您在这里没有使用 inline-block,您使用的是 float ... inline-block 在设置 float 时无用