简体   繁体   English

在Bootstrap中用背景色填充图像

[英]Padding an image in Bootstrap with background colour

Couldn't find an answer to this so.. 找不到答案。

It's probably a very simple solution but I've been tunnel visioning for the past 20 minutes and it's frustrating me. 这可能是一个非常简单的解决方案,但是在过去的20分钟里,我一直在进行隧道愿景,这让我感到沮丧。

The padding of an image, which I'm trying to give a circle background element, is really annoying. 我试图给圆圈背景元素添加图像的填充确实很烦人。

Margin doesn't work either. 保证金也不起作用。

My image is 120 px large, and the padding of 2em just makes it smaller, but I want it to stay the same size, but have a bigger background size. 我的图片是120像素大,而2em的填充只是使其更小,但我希望它保持相同的大小,但具有更大的背景尺寸。

Here's the code: 这是代码:

    <div class="row">
    </div class="container-fluid">
        <div class="col-md-4 img-icon-pad">
            <img src="img/icons/html.png" class="img-responsive img-icons" />
        </div>

        <div class="col-md-4">
            <img src="img/icons/html.png" class="img-responsive img-icons" />
        </div>

        <div class="col-md-4">
            <img src="img/icons/html.png" class="img-responsive img-icons" />
        </div>

    </div>

    /* Boxes */

.img-icons {
    height: 120px;
    width: auto;
    background-color: #f8f8ec;
    border: 2px solid #e97117;
    padding: 2em;
border-radius: 50%;

}

.img-icon-pad {
}

And a screenshot of what I mean: 和我的意思的屏幕截图:

Did you increase the height of .img-icons class from 120 to 150px or bigger if you want. 您是否将.img-icons类的高度从120像素增加到150像素或更大? If that doesn't work then you have probably restricted size of the div containing the img. 如果这不起作用,那么您可能限制了包含img的div的大小。

i think this is what are you trying to do : 我认为这是您想要做的事情:

<div class="row">



        <div class="col-md-4">
        <div class="img-responsive img-icons" >
          <div class="img">

          </div>
        </div>
        </div>



    </div>

css: CSS:

.img-icons {
    height: 120px;
    width:120px;
    background-color: #f8f8ec;
    border: 2px solid #e97117;
   border-radius: 50%;
 padding: 2em;
}
.img{
  text-align:center;
   height:120px;
   width:120px;
     background-color: #f8f8ec;
    border: 2px solid #e97117;
}

you can see the result here https://jsfiddle.net/nt0zqc1t/3/ 您可以在这里查看结果https://jsfiddle.net/nt0zqc1t/3/

I was going to say that in .img-icons class you have width set to auto. 我要说的是,在.img-icons类中,您将宽度设置为auto。 This may be causing resizing. 这可能会导致调整大小。 If you set it to a fixed width it may not resize. 如果将其设置为固定宽度,则可能无法调整大小。

I think it is ok 我觉得还可以

 <div class="row">
    <div class="container-fluid">
        <div class="col-md-4 ">
            <div class="thumbnail">
               <img src="img/icons/html.png" class="img-responsive img-icons" />
            </div>
        </div>

        <div class="col-md-4">
            <img src="img/icons/html.png" class="img-responsive img-icons" />
        </div>

        <div class="col-md-4">
            <img src="img/icons/html.png" class="img-responsive img-icons" />
        </div>

    </div>

    <style>
.thumbnail {
    height: 150px;
    width: 150px;
    border: 2px solid #e97117;
    background-color: #f8f8ec;
     padding: 2em;
}

</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM