响应背景,其高度基于使用引导程序的相邻列

时间:2015-06-16 15:59:46

标签: css twitter-bootstrap

如何在列中创建完整的图像背景但不知道它的高度?我使用bootstrap,我需要图像响应。 请查看image以获得更好的理解

<div class="  col-xs-12 col-sm-5 col-md-5 col-lg-4 bgimage">
 </div>
 <div class="   col-xs-12 col-sm-7 col-md-7 col-lg-8">
</div>
with .bgimage
{
 background-image: url(../img/user.jpg);

    background-size: cover;

}

2 个答案:

答案 0 :(得分:0)

使用body { font-family: sans-serif; background-color: lightseagreen; margin 0; } #widget-container { display: flex; position: fixed; top: 30px; right: 0; bottom: 0; left: 0; } .widget { margin: 15px; background-color: white; flex-grow: 1; border: solid 1px black; } .widget-prio { flex-grow: 3; } .widget-header { padding: 10px 0; width: 100%; text-align: center; background-color: skyblue; } .widget-content-container { display: flex; background-color: lightgrey; padding: 5px; } .widget-textblock { flex-grow: 1; text-align: center; } .widget-textblock-prio { flex-grow: 3; } 将覆盖此框而不会丢失比率。

使用background-size: cover;将填充此框但会丢失比率。

修改

这是背景如何运作的示例。

&#13;
&#13;
background-size: 100%;
&#13;
.table {
  display: table;
  width: 100%;
}

.cell {
  display: table-cell;
}
.cell.left {
  background-image: url(http://oi58.tinypic.com/2u9mo0g.jpg);
  background-size: cover;
}
.cell.right {
  width: 60%;
  padding: 80px 30px;
  background: #ccc;
}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

这是一个包含background-size:cover

的列的bootstrap示例

http://jsfiddle.net/maio/7rbjj2fn/3/

.bgimage{
    background-image: url(http://oi58.tinypic.com/2u9mo0g.jpg);
    background-size: cover;
    height:200px
}
.right{
    background:yellow;
    height:100%;
}
.row{
    background:tomato
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class='row'>
<div class="  col-sm-5 col-md-5 col-lg-4 bgimage">
    </div>
    <div class="right col-sm-7 col-md-7 col-lg-8">
       Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.  nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper