我的手上有一點難題。我有一個應該包含一些圖像的div。圖像不是浮動的 - 我使用display:inline-block獲取了它們。圖像具有一些z-index屬性,因爲懸停時,我會調暗圖像的不透明度並顯示一些文字和一個按鈕。z-index會影響div的高度嗎?
然而,應該只包含不改變其HEIGH圖像調整到其內容的DIV。至於爲什麼,我完全被難住了。調整height屬性將調整部分的大小,但它不會自動調整包含圖像,即使他們的div孩子....
誰能告訴我這是爲什麼發生,如何解決它?
我已經包含了我的html和css的一部分。
<div class="second-section">
<div class="outfitcontainer">
<div class="outfit">
<img src="purelyoutfit6.png" width="100%" height="100%"/>
</div>
<div class="overlay">
<p class="price">$350 <span class="oldprice">$4200</span></p>
<p class="item">FURR COAT</p>
<p class="designer">Antonio Marras</p>
<a href="#"><button type="button" class="btn btn-getit">GET IT</button></a>
</div>
</div>
<div class="outfitcontainer">
<div class="outfit">
<img src="purelyoutfit7.png" width="100%" height="100%"/>
</div>
<div class="overlay">
<p class="price">$350 <span class="oldprice">$4200</span></p>
<p class="item">FURR COAT</p>
<p class="designer">Antonio Marras</p>
<a href="#"><button type="button" class="btn btn-getit">GET IT</button></a>
</div>
</div>
</div>
.outfitcontainer {
position: relative;
width: 200px;
height: 80%;
background-color: #FFFFFF;
display: inline-block;
margin-left: 60px;
margin-top: 20px;
margin-bottom: 20px;
padding: 20px;
}
.outfit img {
display: inline-block;
}
.outfit, .overlay {
position: absolute;
width: 200px;
height: auto;
left: 0;
}
.outfit {
z-index: 10;
background-color: white;
}
.outfitcontainer:hover .outfit {
opacity: .5;
cursor: pointer;
}
.outfit:hover + .overlay{
z-index: 50;
}
.overlay:hover {
z-index: 50;
}
.overlay {
z-index: 0;
text-align: center;
font-weight: bold;
}
.overlay p {
display: block;
padding: 10px 0;
color: black;
opacity: 1;
line-height: 50%;
}
.overlay p:nth-child(1) {
margin-top: 50%
}
.price, .item {
font-family: "Brandon Grotesque Medium";
font-size: 1em;
color: #000000;
line-height: 25%;
margin-top: -10px;
}
.oldprice {
text-decoration: line-through;
color: #383838;
font-size: .75em;
line-height: 25%;
}
.designer {
font-family: "Didot Light Italic";
font-size: 1em;
color: #000000;
line-height: 25%;
margin-top: -15px;
}
.second-section {
width: 100%;
height: auto;
z-index: 50;
background-color: #000000;
}