title: Bootstrap Carousel image position center
body: <p>I'm using the Bootstrap 4 Carousel for my website. Everything is working, but now i'm looking for a solution to align the slider image in the center of the carousel.</p>
  
  <p>Currently it's aligned to the left side, so when i resize the browser, the slider image will be cut of at the right side. I would like to have the image in the center, so that the image will be cut of on both sides.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>/* SLIDER
  -------------------------------------------------- */
  
  /* Carousel base class */
  .carousel {
    margin-bottom: 0;
  }
  /* Since positioning the image, we need to help out the caption */
  .carousel-caption {
    bottom: 3rem;
    z-index: 10;
  }
  
  /* Declare heights because of positioning of img element */
  .carousel-item {
    height: 30rem;
    background-color: #777;
  }
  .carousel-item &gt; img {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 100%;
    height: 40rem;
    margin: 0 auto;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!-- Slider --&gt;
  
            &lt;div id="Slider" class="carousel slide" data-ride="carousel"&gt;
              &lt;ol class="carousel-indicators"&gt;
                &lt;li data-target="#Slider" data-slide-to="0" class="active"&gt;&lt;/li&gt;
                &lt;li data-target="#Slider" data-slide-to="1"&gt;&lt;/li&gt;
                &lt;li data-target="#Slider" data-slide-to="2"&gt;&lt;/li&gt;
              &lt;/ol&gt;
              &lt;div class="carousel-inner"&gt;
                &lt;div class="carousel-item active"&gt;
                  &lt;img class="first-slide" src="img1.jpg" alt="First slide"&gt;
                  &lt;div class="container"&gt;
                    &lt;div class="carousel-caption text-left"&gt;
                      &lt;h1&gt;Platzhalter 1&lt;/h1&gt;
                      &lt;p&gt;Cras justo odio, dapibus ac facilisis in, egestas eget quam.&lt;/p&gt;
                      &lt;p&gt;&lt;a class="btn btn-lg btn-outline-warning" href="#" role="button"&gt;Jetzt buchen&lt;/a&gt;&lt;/p&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="carousel-item"&gt;
                  &lt;img class="second-slide" src="img2.jpg" alt="Second slide"&gt;
                  &lt;div class="container"&gt;
                    &lt;div class="carousel-caption"&gt;
                      &lt;h1&gt;Platzhalter 2&lt;/h1&gt;
                      &lt;p&gt;Cras justo odio, dapibus ac facilisis in, egestas eget quam.&lt;/p&gt;
                      &lt;p&gt;&lt;a class="btn btn-lg btn-warning" href="#" role="button"&gt;Learn more&lt;/a&gt;&lt;/p&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="carousel-item"&gt;
                  &lt;img class="third-slide" src="img3.jpg" alt="Third slide"&gt;
                  &lt;div class="container"&gt;
                    &lt;div class="carousel-caption text-right"&gt;
                      &lt;h1&gt;Platzhalter 3&lt;/h1&gt;
                      &lt;p&gt;Nullam id dolor id nibh ultricies vehicula ut id elit.&lt;/p&gt;
                      &lt;p&gt;&lt;a class="btn btn-lg btn-outline-warning" href="#" role="button"&gt;Browse gallery&lt;/a&gt;&lt;/p&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;a class="carousel-control-prev" href="#Slider" role="button" data-slide="prev"&gt;
                &lt;span class="carousel-control-prev-icon" aria-hidden="true"&gt;&lt;/span&gt;
                &lt;span class="sr-only"&gt;Zurück&lt;/span&gt;
              &lt;/a&gt;
              &lt;a class="carousel-control-next" href="#Slider" role="button" data-slide="next"&gt;
                &lt;span class="carousel-control-next-icon" aria-hidden="true"&gt;&lt;/span&gt;
                &lt;span class="sr-only"&gt;Vor&lt;/span&gt;
              &lt;/a&gt;
            &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/WQlos.png" rel="nofollow noreferrer">Example</a></p>