html - 用图像填充整个 Bootstrap 4 模态主体

标签 html css twitter-bootstrap bootstrap-modal carousel

我有一个包含旋转木马的 Bootstrap 4 模态框,我想用大小为 700px x 450px 的图像填充模态框的整个主体,图像的左/上/右周围没有边框/边距/填充.我希望页脚可见,这样我就可以放置一些文本和一个关闭按钮

这是 Codepen

这是我试图通过图像外观实现的类似示例,请忽略与图像无关的任何内容。

Modal with image

<div class="container">
  <h1 class="display-4 text-center mb-4">Sample Modal</h1>

  <div class="row mb-4">
    <div class="col text-center">
      <a href="#" class="btn btn-lg btn-primary" data-toggle="modal" data-target="#largeModal">Click to open Modal</a>
    </div>
  </div>

  <!-- modal -->
  <div class="modal fade" id="largeModal" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-body">
           <!-- carousel -->
          <div
               id='carouselExampleIndicators'
               class='carousel slide'
               data-ride='carousel'
               >
            <ol class='carousel-indicators'>
              <li
                  data-target='#carouselExampleIndicators'
                  data-slide-to='0'
                  class='active'
                  ></li>
              <li
                  data-target='#carouselExampleIndicators'
                  data-slide-to='1'
                  ></li>
              <li
                  data-target='#carouselExampleIndicators'
                  data-slide-to='2'
                  ></li>
            </ol>
            <div class='carousel-inner'>
              <div class='carousel-item active'>
                <img class='img-size' src='https://images.unsplash.com/photo-1485470733090-0aae1788d5af?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1391&q=80' alt='First slide' />
              </div>
              <div class='carousel-item'>
                <img class='img-size' src='https://images.unsplash.com/photo-1491555103944-7c647fd857e6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80' alt='Second slide' />
              </div>
              <div class='carousel-item'>
                <img class='img-size' src='https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80' alt='Second slide' />
              </div>
            </div>
            <a
               class='carousel-control-prev'
               href='#carouselExampleIndicators'
               role='button'
               data-slide='prev'
               >
              <span class='carousel-control-prev-icon'
                    aria-hidden='true'
                    ></span>
              <span class='sr-only'>Previous</span>
            </a>
            <a
               class='carousel-control-next'
               href='#carouselExampleIndicators'
               role='button'
               data-slide='next'
               >
              <span
                    class='carousel-control-next-icon'
                    aria-hidden='true'
                    ></span>
              <span class='sr-only'>Next</span>
            </a>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
.img-size{
/*  padding: 0;
    margin: 0; */
    height: 450px;
    width: 700px;
    background-size: cover;
    overflow: hidden;
}
.modal-body {
    width: 700px;
    height: 450px;
}

.carousel-control-prev-icon {
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23009be1' viewBox='0 0 8 8'%3E%3Cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E");
    width: 30px;
    height: 48px;
}
.carousel-control-next-icon {
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23009be1' viewBox='0 0 8 8'%3E%3Cpath d='M2.75 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3E%3C/svg%3E");
    width: 30px;
    height: 48px;
}

最佳答案

您应该将 width 放在 .modal-content 而不是 .modal-body 中。并从 .modal-body 中删除 padding。这是修改后的 CSS:

.modal-content {
   width: 700px;
}
.modal-body {
   padding: 0;
}

希望它能解决您的问题。

关于html - 用图像填充整个 Bootstrap 4 模态主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59731187/

相关文章:

html - 如何在CSS中实现效果(见附图)

php - 在 html/css 中排序下拉文本框

javascript - jquery 删除中断标记

css - 适用于所有设备的可重用 html 包装器

html - 导航/标题和媒体查询问题

html - 自定义输入文本框的内置标题栏边框

css - 我在 div 中的最后一个元素溢出,所以只有一半元素可见

javascript - Moment js 给出的星期不正确

twitter-bootstrap - 响应式 SPA 和 VueJS

javascript - 如何通过 bootstrap 中的 selectpicker 插件使用 id 设置选定值