简体   繁体   English

使用Bootstrap 3时图像周围的空白

[英]White space around images when using bootstrap 3

Okay, so I'm making a website using Bootstrap 3 framework, and I have an issue. 好的,所以我正在使用Bootstrap 3框架创建网站,但遇到了问题。 When I put an image (regular one, with an img tag) it has white space (left and right) across the screen. 当我放置一张图片(带有img标签的普通图片)时,它在屏幕上有空白(左右)。 http://prntscr.com/9wuek5 - you can see that here, it even goes under my navbar. http://prntscr.com/9wuek5-您可以在这里看到它甚至在我的导航栏中。 What I want to do is somehow get rid of that white space, and move picture to the center (horizontally and vertically). 我想做的就是以某种方式摆脱该空白,然后将图片移动到中心(水平和垂直)。 Here is my code so far: 到目前为止,这是我的代码:

<nav id="mainNavbar" class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#colaps">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">ivke11080</a>
        </div>
        <div class="collapse navbar-collapse" id="colaps">
            <ul class="nav navbar-nav navbar-right">
                <li><a class="page-scroll" href="#">Home</a></li>
                <li><a class="page-scroll" href="#">Projects</a></li>
                <li><a class="page-scroll" href="#portfolio">About</a></li>
            </ul>
        </div>
    </div>
</nav>

<img src="img/chase.jpg"/>

I tried to put border around image so i can see if it applies to the white space, but it's not, it's just around image as it should be. 我尝试在图像周围放置边框,以便可以看到它是否适用于空白区域,但事实并非如此,它只是应在图像周围。

You can absolutely position your image by using the following styles: 您可以使用以下样式来绝对定位图像:

img{
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%, 50%);
}

See this fiddle 看到这个小提琴

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

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