具有边框和填充的引导圆类元素

时间:2018-08-22 16:19:31

标签: jquery html css twitter-bootstrap bootstrap-4

我有一个带有多个项目的引导轮播。

我的html:

<div class="carousel w-100 " data-ride="carousel" id="recipeCarousel">
   <div class="carousel-inner w-100" role="listbox">
        <div class="carousel-item active">
            <img class="d-block col-sm-12 col-md-4 rounded-circle mystyle"  src="{% static 'core/src/img/staff_member_01.jpg'%}">
            <img class="d-block col-sm-12 col-md-4 rounded-circle mystyle" src="{% static 'core/src/img/staff_member_02.jpg'%}">
            <img class="d-block col-sm-12 col-md-4 rounded-circle mystyle"  src="{% static 'core/src/img/staff_member_03.jpg'%}">
        </div>
        [...]
  </div>
</div>

我的CSS:

.mystyle{
 border:1px solid #d3232e;
}

如下面的屏幕快照所示,我的问题是我需要在图像之间添加一些填充(由引导网格系统处理),这会破坏边框布局。

enter image description here

如果我使用边距并删除填充

.mystyle{
  margin: 0 0.4em;
  padding: 0!important;
  border:1px solid #d3232e;
}

enter image description here

帮助! :-)

谢谢

编辑1 解决了摆在这里的问题后,我写了new question来解决轮播jQ损坏的问题。

2 个答案:

答案 0 :(得分:2)

您应该将图像放在col divs内,并使用img-fluid ...

<div class="carousel w-100" data-ride="carousel" id="recipeCarousel">
    <div class="carousel-inner text-center w-100" role="listbox">
        <div class="carousel-item d-flex row active">
            <div class="col-sm-12 col-md-4"><img class="rounded-circle img-fluid mystyle" src="//placehold.it/300"></div>
            <div class="col-sm-12 col-md-4"><img class="rounded-circle img-fluid mystyle" src="//placehold.it/300"></div>
            <div class="col-sm-12 col-md-4"><img class="rounded-circle img-fluid mystyle" src="//placehold.it/300"></div>
        </div>
    </div>
</div>

那么就不会有重叠。

https://www.codeply.com/go/b7DE9Q6AOm

答案 1 :(得分:1)

将每个图像放入容器中。

.round-container{
  display:inline-block;
  margin:10px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>


<div class="round-container">
<img class="rounded-circle" src="https://via.placeholder.com/100x100" width="100">
</div>

<div class="round-container">
<img class="rounded-circle" src="https://via.placeholder.com/100x100" width="100">
</div>

<div class="round-container">
<img class="rounded-circle" src="https://via.placeholder.com/100x100" width="100">
</div>