2014-09-24 37 views
12

我使用自举和具有问题在图像上叠加字幕,字幕DIV只是不能配合在盒中,如下所示:引导3 CSS图象字幕叠加

enter image description here

HTML:

<div class="col-sm-4"> 
    <a href="#"> 
     <img src="images/upload/projects/21/wolf.jpg" class="img-responsive" alt="" /> 
     <div class="desc"> 
      <p class="desc_content">The pack, the basic unit of wolf social life.</p> 
     </div> 
    </a> 
</div> 

<div class="col-sm-4"> 
    <a href="#"> 
     <img src="images/upload/projects/21/cake.png" class="img-responsive" alt=""> 
     <div class="desc"> 
      <p class="desc_content">The pack, the basic unit of wolf social life.</p> 
     </div> 
    </a> 
</div> 

CSS:

div.desc{ 
    position: absolute; 
    bottom: 0px; 
    width: 100%; 
    background-color: #000; 
    color: #fff; 
    opacity: 0.5; 
    filter: alpha(opacity=50); 
} 

SOLUTION:

由于@himanshu来解决这个问题。

div.desc{ 
    background-color: #000; 
    bottom: 0; 
    color: #fff; 
    left: 0; 
    opacity: 0.5; 
    position: absolute; 
    width: 100%; 
} 

.fix{ 
    width: 100%; 
    padding: 0px; 
} 
+0

尝试使用盒大小:边界盒;对于p.desc_content类 – 2014-09-24 06:46:18

+0

@Vitorino费尔南德斯,没有运气! – conmen 2014-09-24 06:48:59

+0

尝试删除宽度:100%并添加左侧:0;右:0;对于div.desc – 2014-09-24 07:00:28

回答

3

我认为问题出在位置而不是叠加,div.desc是绝对的,形象是它的兄弟。因此覆盖图不会跟随图片,它只会跟随锚标签或您的div.wrapper

从我所看到的是,在图像或填充锚或包装上有一个边距。

最好的解决方案是将desc和图像放在另一个div中,使用0填充的宽度为100%。

<div class="col-sm-4 wrapper"> 
    <a href="#"> 
<div class="fix"> 
     <img src="images/upload/projects/21/wolf.jpg" class="img-responsive" alt="" /> 
     <div class="desc"> 
      <p class="desc_content">The pack, the basic unit of wolf social life.</p> 
     </div></div> 
    </a> 
</div> 

CSS:

.fix{width:100%; padding:0px;} 
+0

它不适合在框中,就像我编辑的帖子一样。 – conmen 2014-09-24 07:31:40

+0

use div.desc {width:100%;} – himanshu 2014-09-24 07:35:50

+0

give position:relative; .fix { 宽度:100%; padding:0px; 位置:相对; } – Cavid 2016-04-20 08:43:12

1

使用此属性div.desc类

div.desc{ 
    position: absolute; 
    bottom: 0; 
    background-color: #000; 
    color: #fff; 
    opacity: 0.5; 
    left:0; /** new **/ 
    right:0; /** new **/ 
    filter: alpha(opacity=50); 
} 
2

试试这个

<div class="wrapper"> 
    <div class=""> 
     <img src="images/upload/projects/21/wolf.jpg" class="img-responsive" alt="" > 
    </div> 
    <div class="desc_content" style="">The pack, the basic unit of wolf social life.</div> 
</div> 
<div class="wrapper"> 
    <div class=""> 
     <img src="images/upload/projects/21/wolf.jpg" class="img-responsive" alt="" > 
    </div> 
    <div class="desc_content" style="">The pack, the basic unit of wolf social life.</div> 
</div> 

CSS

div.desc_content { 
background-color: #000; 
color: #FFF; 
font: bold 11px verdana; 
padding-left: 10px; 
padding-top: 7px; 
height: 23px; opacity: 0.7; 
position: relative; 
top: -30px; 
} 
div.wrapper{ 
    float: left; 
    position: relative; 
    margin: 10px; 
}