简体   繁体   English

超大屏幕图像未居中

[英]jumbotron image is not centered

I have the following code for the header.我有以下标题代码。 The image is not centered when I change to different sizes.当我更改为不同尺寸时,图像未居中。 How can I center the image for all size views.如何将所有尺寸视图的图像居中。

  <div class="jumbotron">
        <img src="images/header.jpg" alt="Banner" class="img-responsive">
   </div>

You can use with this changes on your css file :您可以在 css 文件上使用此更改:

// Center all elements in jumbotron, if <img> is not in display block
.jumbotron{
    text-align:center;
}

Or this, more specific (I prefer) :或者这个,更具体的(我更喜欢):

// Set the <img> in display block and use margin auto to center
.jumbotron img{
    display:block;
    margin-left:auto;
    margin-right:auto;
}

If I'm not wrong, what you want to do here is make the image centered in the middle of your .jumbotron .如果我没记错的话,您在这里要做的是使图像居中在您的.jumbotron中间。 For this, you can useCSS Flexbox :为此,您可以使用CSS Flexbox

 .jumbotron { display: flex; justify-content: center; align-items: center; }
 <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="jumbotron"> <img src="images/header.jpg" alt="Banner" class="img-responsive"> </div>

This will center the img in the exact center of the .jumbotron , both horizontally and vertically.这将使img居中在.jumbotron的确切中心,水平和垂直。

Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM