2015-09-02 43 views

回答

1

我想這將滿足您的需要,調整細節元素的高度,只需編輯裏面.details

html * { 
 
    box-sizing: border-box; 
 
} 
 
.crop { 
 
    background-image: url('http://cs628119.vk.me/v628119319/10059/Ag3oy3YU6wY.jpg'); 
 
    width: 200px; 
 
    height: 150px; 
 
    background-position: center; 
 
    background-size: cover; 
 
    position: relative; 
 
    overflow: hidden; 
 
} 
 
.shape { 
 
    width: 200px; 
 
    height: 50px; 
 
    color: black; 
 
} 
 
.details { 
 
    position: absolute; 
 
    bottom: -100%; 
 
    left: 0; 
 
    right: 0; 
 
    height: 100%; 
 
    background: rgba(0, 0, 0, 0.5); 
 
    padding: 5px 10px; 
 
    transition: all 1s; 
 
    color: white; 
 
} 
 
.crop:hover > .details { 
 
    bottom: 0; 
 
}
<div class="shape"> 
 
    <div class="crop"> 
 
    <div class="details"> 
 
     Yes, this is cat! 
 
    </div> 
 
    </div> 
 
</div>

+0

height:值當然這裏有一個* * [fiddle](http://jsfiddle.net/j2aqmv6r/1/)**,但我認爲你的問題可能是這樣的 - 你忘了將'position:relative'添加到'.crop' –