試試這個:
<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