Bootstrap:如何将图像与浏览器边框对齐?

时间:2016-03-13 00:34:32

标签: css html5 image twitter-bootstrap-3 alignment

illustration of what i want

我想让一些div将相应的图像对齐到浏览器边框(每个div的左侧或右侧)。

有没有办法在不使用JS的情况下完成?

至于现在我使用图像作为容器流体的背景:

<div class="container-fluid diamondBG">
    <div class="container">
      <div class="row" style="text-align:center;">
        <div style="display:inline-block; float:none; text-align:left;" class="col-md-9">
            Some text
        </div>
      </div>
    </div>
  </div>

CSS:

.diamondBG{
    background-image: url('images/diamondLarge.png');
    background-position: right;
    background-repeat: no-repeat;
 }

这不是解决方案,因为bg图像被裁剪到div的高度。不得指定div的高度。

2 个答案:

答案 0 :(得分:0)

解决方案是&#34;位置:绝对&#34;和&#34;右:0&#34;或&#34;左:0&#34;在容器流体中:

<div class="container-fluid">
    <img src="images\diamondLarge.png" style="position:absolute; right:0; margin-top:-60px;">
    <div class="container">
      <div class="row" style="text-align:center;">
        <div style="display:inline-block; float:none; text-align:left;" class="col-md-9">
            Some text
        </div>
      </div>
    </div>
</div>

答案 1 :(得分:-1)

嘿,我会帮助你

<!DOCTYPE html>
<html>
<head>
    <title>ayuda</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <style type="text/css">
        *{
            padding:0 !important;
        }
    </style>
</head>
<body>

<div class="container-fluid">
  <div class="row">
    <div class="col-md-offset-10 col-md-2">
      <img src="http://urdunovels.info/wp-content/uploads/2015/03/green-city-gandhinagar-portal-bg.jpg" width="200"/>
    </div>
    <div class="col-md-2">
      <img src="http://urdunovels.info/wp-content/uploads/2015/03/green-city-gandhinagar-portal-bg.jpg" width="200"/>
    </div>
    <div class="col-md-offset-10 col-md-2">
      <img src="http://urdunovels.info/wp-content/uploads/2015/03/green-city-gandhinagar-portal-bg.jpg" width="200"/>
    </div>
    <div class="col-md-2">
      <img src="http://urdunovels.info/wp-content/uploads/2015/03/green-city-gandhinagar-portal-bg.jpg" width="200"/>
    </div>
  </div>
</div>

</body>
</html>