2014-06-19 62 views
0

我试图在缩略图图像上放置一个按钮,但在图像后面的标题区域添加了该按钮。 下面是代码:在缩略图图像上显示一个按钮

<div class="thumbnail"> 
    <img class="img-responsive"alt="300x200" src="network_sec.jpg"> 
    <button class="btn btn-default btn-warning pull-right"><span class="glyphicon glyphicon-user"></span> 10</button> 

    <div class="caption"> 
     <h3 align="center">Network Security</h3> 
     <br> 
     <p> 
     <button class="btn btn-default btn-danger"><span class="glyphicon glyphicon-wrench"></span> Manage</button> 
      <button class="btn btn-default btn-danger"><span class="glyphicon glyphicon-eye-open"></span> Preview</button> 
      <button class="btn btn-default btn-danger"><span class="glyphicon glyphicon-pencil"></span> Edit Info</button> 
     </p> 
    </div> 
</div> 

我想在图像的右下部分对齐按钮。关于如何达到预期结果的任何建议?

+0

使用位置绝对值为缩略图和缩略图和按钮容器的按钮和位置相对位置 –

+0

试试这个 -

回答

2

我会把图像放在一个新的div的按钮,然后使用定位相对和绝对像这样。

HTML

<div class="thumbnail"> 
    <div id="thumb"> 
    <img class="img-responsive"alt="300x200" src="network_sec.jpg"> 
    <button class="btn btn-default btn-warning pull-right"><span class="glyphicon glyphicon-user"></span> 10</button> 
    </div> 
    <div class="caption"> 
    <h3 align="center">Network Security</h3> 
    <br> 
    <p> 

    <button class="btn btn-default btn-danger"><span class="glyphicon glyphicon-wrench"></span> Manage</button> 
    <button class="btn btn-default btn-danger"><span class="glyphicon glyphicon-eye-open"></span> Preview</button> 
    <button class="btn btn-default btn-danger"><span class="glyphicon glyphicon-pencil"></span> Edit Info</button> 
</p> 

</div> 
</div> 

CSS

#thumb 
{ 
    position: relative; 
    width: 300px; 
    height: 200px; 
} 

#thumb img 
{ 
    z-index: 1; 
    position: absolute; 
    width: 300px; 
    height:200px; 
    top: 0; 
    left: 0; 

} 
#thumb button 
{ 
    z-index: 5; 
    position: absolute; 
    bottom: 0; 
    right: 0; 
} 

是你脑子里想的是什么?

+0

是的,按钮的位置是我想要的,但它现在调整了整个图像的大小。我希望图片保持原始尺寸。 – leMS

+0

我不确定这个图片的大小是基于你的html的,但是我看到200x300这么猜对了。您可以更改拇指和img样式的宽度和高度。 –

+0

正确,但图像不再保持与自定义高度和宽度的响应。我该如何解决这个问题? – leMS