【问题标题】:Unwanted right margin in Owl Carousel猫头鹰轮播中不需要的右边距
【发布时间】:2026-02-15 03:35:02
【问题描述】:

我正在尝试在页面的标题部分制作全高和全宽滑块。为此,我正在使用 owl carousel 和 bootstrap。一切正常,但我得到了一些我不想要的正确边距。我确实重置了页面的边距和填充,但是当我使用 owl carousel 时,我得到了正确的边距。请帮助我如何摆脱这个边距。

这里是代码。

HTML

<div class="header">
    <div class="container-fluid">
        <div class="row owl-carousel">
          <div class="item d-flex flex-row">
            <div class="left">hello</div>
            <div class="right">world</div>
        </div>
        <div class="item d-flex flex-row">
          <div class="left one">hello</div>
          <div class="right two">world</div>
      </div>
      </div>
    </div>
  </div>

CSS

*{
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
body{
  font-family: 'Roboto', sans-serif;

}

.left{
  height:100vh;
  width:30%;
  background-color: red;

}
 .right{
  height:100vh;
  width:70%;
  background-color: green;
}

.one{
  background-color: yellow;
}
.two{
  background-color: orange;
}

JS

$('.owl-carousel').owlCarousel({
    loop:true,
    nav:false,
    autoplay:true,
    autoplayTimeout:4000,
    items:1

});

【问题讨论】:

    标签: html css twitter-bootstrap owl-carousel


    【解决方案1】:

    你需要在div.row中添加新的div:

    工作示例:jsfiddle

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
    </head>
    <body>
      <div class="header">
        <div class="container-fluid">
            <div class="row">
              <div class="owl-carousel">
                <div class="item d-flex flex-row">
                  <div class="left">hello</div>
                  <div class="right">world</div>
              </div>
              <div class="item d-flex flex-row">
                <div class="left one">hello</div>
                <div class="right two">world</div>
              </div>
             </div>
          </div>
        </div>
      </div>
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      在js中添加边距值

      margin:0,
      

      【讨论】: