jeudi 28 juin 2018

How to center those images in Bootstrap?

Hey there stackoverflow

I am trying to center those images. I tried everything I found about vertical centering in bootstrap.

http://jsfiddle.net/tLd85urn/1/

Here you can see my sourcecode. If I remove the lines on "div" and "html" in the CSS stylesheet (height: 100%;), the images seems centered, but the whole page is stacked together. How can I center those images, and keep the "fullscreen" layout?

HTML

<div class="container-fluid">
      <div class="row header text-center align-items-center align-middle">
        <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
        <div class="col-xl-8 col-lg-8 col-md-8 col-sm-6 col-6" style="background-color:lavenderblush;">.col-lg-8</div>
        <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
      </div>
      <div class="row content text-center align-items-center align-middle">
        <div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="background-color:lavender;">.col-lg-1</div>
        <div class="align-items-center align-middle col-xl-10 col-lg-10 col-md-10 col-sm-10 col-10" style="background-color:blue;">.col-lg-10<img src="test2.png" class="align-items-center align-middle img-fluid rounded mx-auto" alt="Responsive image"><img src="test2.png" class="img-fluid mx-auto" alt="Responsive image"><img src="test2.png" class="img-fluid mx-auto" alt="Responsive image"></div>
        <div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="background-color:lavender;">.col-lg-1</div>
      </div>
      <div class="row footer text-center">
        <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
        <div class="col-xl-8 col-lg-8 col-md-8 col-sm-6 col-6" style="background-color:lavenderblush;">.col-lg-8</div>
        <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2<img src="test3.png" class="img-fluid rounded mx-auto" alt="Responsive image"></div>
      </div>
    </div>

CSS

html,
body {
  height: 100%; /* If I remove this line, it works, but its no more fullscreen */
  width: 100%;  
  margin: 0;
}

div {
  height: 100%; /* If I remove this line, it works, but its no more fullscreen */
  /*width: 100%; */
  margin: 0;
}

.header {
  height: 10% !important;
}

.content {
  height: 80% !important;
}

.footer {
  height: 10% !important;
}

Thanks for your help and greetings,

Tine




Aucun commentaire:

Enregistrer un commentaire