[英]Unwanted white space around image inside div
I need to display an image inside a div
with bootstrap
and there's an uncalled for white space around the image. 我需要在带有
bootstrap
的div
显示一个图像,并且图像周围有一个未调用的空白区域。 This is what it looks like: 这就是它的样子:
I'm not talking about the white background - it's intentional. 我不是在谈论白色背景 - 这是故意的。 I am talking about the fact the image doesn't stretch to the width of the
div
. 我说的是图像没有伸展到
div
的宽度。 This is the code I'm using: 这是我正在使用的代码:
<div align="center" class="col-xs-3 col-sm-2 col-md-3 whitebgdiv" style="border:0px solid red; margin-top:5px; margin-bottom:5px; margin-left:5px;">
<a href='#{product.itemUrl}' target="_blank"><img src='#{product.thumbnailUrl}' style="border: 0px solid blue;" class="img-responsive productimg vertical-align2" /></a> <br/>
</div>
The relevant css
classes: 相关的
css
类:
.whitebgdiv {
background-image:url('../resources/images/whitebg.jpg');
border-radius: 2px;
margin-left:0px;
}
.productimg {
width: 6em;
max-width: 180px;
}
I tried display:block
and display:inline
but they do nothing. 我试过
display:block
和display:inline
但它们什么都不做。 What am I missing? 我错过了什么?
Try this: 尝试这个:
.productimg{
width: 100%;
height: auto;
}
If the width of its container is defined, you don't need to set a max-width on the image either with this code. 如果定义了其容器的宽度,则无需使用此代码在图像上设置最大宽度。
使用宽度100%并删除最大宽度。
.productimg { display:block; width: 100%; height:auto;}
Remove the width to image the white space is due to max-width
to image tag. 删除宽度以使图像空白是由于
max-width
到图像标记。 the container(div) with is higher then the image width so your getting white space between those 容器(div)高于图像宽度,因此您可以在它们之间获得空白
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.