试试这个:
<div id="parent">
<div id="a" style="float: left;">Hello</div>
<div id="b" style="float: right;">World!</div>
<div style="clear: both;"></div>
</div>
需要的东西在它的中间?
<div id="parent">
<div id="a" style="float: left;">Hello</div>
<div id="b" style="float: right;">World!</div>
<div style="text-align: center;">holy schmoley</div>
<div style="clear: both;"></div>
</div>
现在在一起。
<style type="text/css">
#a {
float: left;
}
#b {
float: right;
}
#c {
text-align: center;
}
.clear {
clear: both;
}
</style>
<div id="parent">
<div id="a">Hello</div>
<div id="b">World!</div>
<div id="c">holy schmoley</div>
<div class="clear"></div>
</div>
等于高度:
<style type="text/css">
#a, #b, #c {
height: 100%;
}
#a {
background-color: #ff0000;
float: left;
}
#b {
background-color: #00ff00;
float: right;
}
#c {
background-color: #0000ff;
text-align: center;
}
.clear {
clear: both;
}
</style>
<div id="parent">
<div id="a">Hello</div>
<div id="b">World!</div>
<div id="c">holy schmoley</div>
<div class="clear"></div>
</div>
对齐于底部使用绝对,我建议添加缘至#C div来防止任何奇数重叠:
<style type="text/css">
#parent {
position: relative;
}
#a, #b {
position: absolute;
bottom: 0;
}
#a {
background-color: #ff0000;
}
#b {
background-color: #00ff00;
right: 0;
}
#c {
background-color: #0000ff;
text-align: center;
}
.clear {
clear: both;
}
</style>
<div id="parent">
<div id="a">Hello</div>
<div id="b">World!</div>
<div id="c">holy schmoley<br /><br /><br /></div>
<div class="clear"></div>
</div>
浮动使用Flex
<style type="text/css">
#container {
/* width: 600px; */
}
#parent {
position: relative;
}
#a {
display: flex;
float: left;
justify-content: space-between;
width: 100%;
}
#b {
background-color: #ff00ff;
float: left;
width: 100px;
}
#c {
background-color: #00ff00;
float: right;
width: 100px;
}
#d {
padding: 0 100px 0 100px;
width: inherit;
}
#e {
background-color: #ff0000;
}
</style>
<div id="container">
<div id="parent">
<div id="a">
<div id="b">Hello</div>
<div id="c">
World!
<br /><br /><br /><br /><br /><br />
</div>
</div>
<div id="d">
<div id="e">
<br /><br /><br /><br /><br /><br />Heres my content!!<br /><br /><br /><br /><br /><br />
</div>
</div>
</div>
</div>
© Copyright
浮球随弯曲,底部定位:
<style type="text/css">
#container {
/* width: 600px; */
}
#parent {
position: relative;
}
#a {
bottom: 0;
display: flex;
float: left;
justify-content: space-between;
position: absolute;
width: 100%;
}
#b {
background-color: #ff00ff;
float: left;
width: 100px;
}
#c {
background-color: #00ff00;
float: right;
width: 100px;
}
#d {
padding: 0 100px 0 100px;
width: inherit;
}
#e {
background-color: #ff0000;
}
</style>
<div id="container">
<div id="parent">
<div id="a">
<div id="b">Hello</div>
<div id="c">
World!
<br /><br /><br /><br /><br /><br />
</div>
</div>
<div id="d">
<div id="e">
<br /><br /><br /><br /><br /><br />Heres my content!!<br /><br /><br /><br /><br /><br />
</div>
</div>
</div>
</div>
© Copyright
使用Flex浮筒底部为您的整个页面布局:
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#container {
height: 100%;
}
#parent {
position: relative;
height: 100%;
}
#a {
display: flex;
float: left;
justify-content: space-between;
width: 100%;
position: absolute;
bottom: 0;
}
#b {
background-color: #ff00ff;
width: 100px;
float: left;
}
#c {
background-color: #00ff00;
width: 100px;
float: right;
}
#d {
bottom: 0;
left: 100px;
right: 100px;
position: absolute;
}
#e {
background-color: #ff0000;
}
</style>
<div id="container">
<div id="parent">
<div id="a">
<div id="b">Hello</div>
<div id="c">
World!
<br /><br /><br /><br /><br /><br />
</div>
</div>
<div id="d">
<div id="e">
Heres my content!!<br /><br /><br />
</div>
</div>
</div>
</div>
你的要求不明确。看来你希望A和B的宽度和高度相对于父母相等。 – TeaCode
你的意思是http://codepen.io/gc-nomade/pen/pyWJRL? –
@Gyryrillus是的,这就是我想要的。 A和B内部的文本与底部对齐,而不是正常的顶部。 – Fallenreaper