使用 html 设置轮播的宽度

Setting the width of a carousel using html

我曾尝试减小轮播的宽度,使其不会占据页面的整个宽度,但它似乎不起作用。我希望宽度仅跨越 8 列并居中。我尝试更改 CSS 代码,使宽度为 50% 而不是 100%,但这没有用。

.item {
  height: 300px;
}

.item,
img {
  height: 500px !important;
  width: 100% !important;
}

.item h3 {
  font-family: 'Anton', sans-serif;
  font-size: 48px;
  color: cornsilk;
}

.item p {
  font-family: 'Anton', sans-serif;
  font-size: 18px;
  color: cornsilk;
}
<!--Start of carousel-->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"> </li>
    <li data-target="#carousel-example-generic" data-slide-to="1"> </li>
    <li data-target="#carousel-example-generic" data-slide-to="2"> </li>
  </ol>
  <div class="carousel-inner">
    <div class="item active">
      <img src="images/c1.jpg" alt="First slide" />

      <div class="carousel-caption">
        <h3>Welcome to my amazing website</h3>
        <p3>Hope you enjoy!</p3>

      </div>
    </div>
    <div class="item">
      <img src="images/c2.jpg" alt="Second slide" />
    </div>
    <div class="item">
      <img src="images/c3.jpg" alt="Third slide" />
    </div>
  </div>
  <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
  <a class="right carousel-control" href="#carousel-example-generic" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>

为什么不使用上层,即外部 div 元素 (id="carousel-example-generic" class="carousel slide")?

例如

.carousel{
  width: 50%;
  margin: 0 auto;
}

对于 bootstrap,您还可以使用 bootstrap-网格,包括偏移量:https://getbootstrap.com/docs/4.0/layout/grid/