我有一個圖像和一些文本在p標籤和鏈接垂直對齊。當我浮動圖像時,它可以很好地工作。但是當我在p標記和鏈接中使用填充時,它不能完美地填充填充。
click here to see the image I need look like
here is a fiddle圖像和多行文本和鏈接垂直對齊
.wrapper {
font-family: sans-serif;
width: 400px;
margin-top: 30px;
margin-bottom: 30px;
clear:both
}
img {
float: left;
}
p.text {
padding-left: 30px;
display: block;
padding-bottom: 22px;
color: #222222;
}
a.link {
text-decoration: none;
padding-left: 30px;
text-transform: uppercase;
line-height: 22px;
color: #777777;
}
a.date {
color: #e10622;
text-decoration: none;
}
<div class="wrapper">
<img src="https://placehold.it/100x100" alt="">
<p class="text">Posted By: Simon | <a href="#" class="date"> 26 July 2016</a></p>
<a href="#" class="link">Days are all happiness is key
and Free</a>
</div>
<div class="wrapper">
<img src="https://placehold.it/100x100" alt="">
<p class="text">Posted By: Simon | <a href="#" class="date"> 26 July 2016</a></p>
<a href="#" class="link">Days are all happiness is key
and Free</a>
</div>
<div class="wrapper">
<img src="https://placehold.it/100x100" alt="">
<p class="text">Posted By: Simon | <a href="#" class="date"> 26 July 2016</a></p>
<a href="#" class="link">Days are all happiness is key
and Free</a>
</div>
<br>
<br>
<br>
<a href="http://prntscr.com/cpusej" style="text-align:center; display: block; padding: 10px; background: #f44; font-size: 18px">Please see here what I need</a>
在此先感謝。 :)
它解決了我的問題:)。但我很想知道爲什麼我必須在img中提供保證金。文本有什麼問題? –
有兩個原因。首先,你只需要在一個地方而不是兩個地方設置/更新它。其次,由於圖像上的浮動,它旁邊元素(即'p.text'和'a.link'元素)上的任何填充或邊距都會完全忽略圖像。由於您的圖片大小爲100px,因此您的元素在觸碰填充/邊距邊界之前會碰到圖片。你可以將'margin-left'或'padding-left'設置爲'130px',這在技術上是可行的,但將它放在圖像上看起來更清晰。 – manwill
非常感謝。抱歉打擾你。因爲我是一個新的學習者,它肯定會對我有所幫助。 祝你有美好的一天:) –