我可能真的很累,但我不能爲了我的生活找出爲什麼display: inline-block
不能使父母的寬度適應其內容的大小。我試過尋找其他的解決方案,但是我發現的每一個資源都說要把inline-block
加到父母身上才行。爲什麼父母不會調整它的內容寬度?
在下面的例子中,我試圖讓藍方只延伸到綠色廣場的邊緣,然後最終通過margin: 0 auto;
中心內容:
#intro {
height: 400px;
background-color: red;
}
.slide-txt {
display: inline-block;
width: 30%;
background-color: lime;
}
.slide-box {
display: inline-block;
margin: 0 auto;
background-color: blue;
}
<section id="intro" class="image-slider">
<div class="container" id="intro-slide">
<div class="slide-box">
<img src="http://www.jkoffset.com/assets/images/Packaging1.jpg" alt="same-box-slide" width="150px">
<div class="slide-txt">
<h1 class="title">Headline <span>Goes Here</span></h1>
<div class="caption"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a class="btn" href="#">
Learn More
</a>
</div>
</div>
</div>
</div>
</section>
https://jsfiddle.net/eam0mk47/
請勿在此類中使用寬度%.slide-txt ...使用px代替 – Chiller
這樣做。謝謝。如果您將其作爲答案提交,我會將其標記爲已解決。 – Heather