做出的第二個元素浮動權
請參閱Working Fiddle
HTML:
<div class="First"></div>
<div class="Second"></div>
<div class="Third"></div>
CSS:
div
{
float: left;
width: 50%;
}
.First
{
height: 50px;
background-color: red;
}
.Second
{
height: 90px;
background-color: yellow;
float: right;
}
.Third
{
height: 50px;
background-color: green;
}
編輯:如果你有數目不詳的div的, 像這樣HTML(改變大小,只要你想)
<div style="height: 50px;"></div>
<div style="height: 90px;"></div>
<div style="height: 70px;"></div>
<div style="height: 50px;"></div>
<div style="height: 90px;"></div>
<div style="height: 70px;"></div>
<div style="height: 50px;"></div>
<div style="height: 90px;"></div>
<div style="height: 70px;"></div>
只要使用這個CSS:
div
{
width: 48%;
margin: 1%;
background-color: #09F;
}
div:nth-child(odd)
{
float: left;
}
div:nth-child(even)
{
float: right;
}
看看這個Working Fiddle
小提琴請.. – avrahamcool
@avrahamcool酷,只要給我兩秒 – proPhet
根據嚴格的描述,沒有JavaScript,由於規則#5 http://www.w3.org/TR/CSS2/ visuren.html#float-position – j08691