我有三個元素,一個是標題,另一個是段落,另一個是圖像。現在,我希望圖像浮動到右側,讓標題和段落浮動到左側和底部,如「圖片1」。當嵌入塊移動到圖像底部時,刪除圖像的浮動屬性
爲了不縮小標題和縮小外部div (藍框),我在標題上使用display:inline-block
。
但是,這裏的問題: 如果我縮小外部div的寬度,使標題移動到圖像的底部,圖像仍然對齊到右側,如「圖像3」。但是我需要什麼就像「圖像2」一樣,圖像應該與左邊對齊。
如果內嵌塊標題移動到圖像的底部,是否有任何方法可以刪除圖像的浮動屬性?
#div0{
width: 1000px;
}
#div1{
width: 550px;
}
.outer{
margin: 20px 0;
border: 1px solid blue;
}
.image{
float: right;
}
.title{
display: inline-block;
}
.paragraph{
}
<div id="div0" class="outer">
<img src="http://www.w3school.com.cn/i/eg_tulip.jpg" class="image" />
<h1 class="title">This Is the Title...</h1>
<div class="paragraph">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div>
</div>
<div id="div1" class="outer">
<img src="http://www.w3school.com.cn/i/eg_tulip.jpg" class="image" />
<h1 class="title">This Is the Title...</h1>
<div class="paragraph">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div>
</div>
但我怎麼會知道寬度的值,如果寬度不固定? (我不想用Javascript來解決這個問題) –
@BananaCode如果你使用chrome打開開發者模式,你可以在調整大小時看到當前瀏覽器窗口的寬度。使用它來確定圖像何時需要丟失其浮點數。 – Gezzasa