2015-04-28 100 views
0

我有一個包含一些CSS轉換圖像的div。 我想在這個div裏面做一個標題,顯示在底部,包含圖像的頂部。重要的是我需要將標題顯示在框內而不是框外。試圖顯示包含圖像的div內的標題

以下是我有:

.t_box { 
     width: 250px; 
     height: 155px; 
     background-color: #ccc; 
     border: 5px solid #FF0000; 
     position: relative; 
     z-index: 40; 
     overflow:hidden; 

} 
.t_box img { 
     max-width: 100%; 
     opacity: 0.6; 
     transition: all 0.4s ease-in-out; 
     -moz-transition: all 0.4s ease-in-out; 
     -webkit-transition: all 0.4s ease-in-out; 
     -o-transition: all 0.4s ease-in-out; 
} 
.t_box img:hover { 
     opacity: 1; 
     -ms-transform: scale(1.3); 
     /* IE 9 */ 
     -webkit-transform: scale(1.3); 
     /* Chrome, Safari, Opera */ 
     transform: scale(1.3); 
} 
.t_caption { 
     width: 100%; 
     height: 40px; 
     background-color: #666; 
     color: #fff; 
     z-index: 50; 

     position: absolute; 
} 

和HTML:

<div class="t_box"> 
    <img src="image.jpg" /> 
    <div class="t_caption">This is a caption</div> 
</div> 

這裏是小提琴的鏈接:http://jsfiddle.net/seenvvty/

+0

將底部0加到'.t_caption'。 – dowomenfart

+0

這是你在http://jsfiddle.net/j08691/q81rrdwf/? – j08691

回答

1

t_caption CSS添加bottom:0;

.t_caption { 
    width: 100%; 
    height: 40px; 
    background-color: #666; 
    color: #fff; 
    z-index: 50; 
    position: absolute; 
    bottom:0; 
} 

JSFiddle