I'm trying to place a background image so it will fit the full width of the page, and support the content of the bootstrap grid (not fixed height), while my container has a fixed width.
I've tried to use 2 approches :
- As background url
- As img element with position absolute with 100% width
The first option the img doesn't cover all of the content and in the second option the img does not support dynamic height.
Is there a way to achieve what I want or it is just not possible when the .container class has fixed width? Is there a better way?
/* Styles go here */
.container {
width: 300px;
text-align: center;
color: white;
}
.myImg {
background: url('http://data.whicdn.com/images/10274608/large.jpg');
background-size: cover;
width: 100%;
height: auto;
}
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap@*" data-semver="4.0.0-alpha.2" rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css" />
<script data-require="bootstrap@*" data-semver="4.0.0-alpha.2" src="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/js/bootstrap.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="container">
<div class="myImg">
<div class="row">
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
</div>
</div>
</div>
<hr/>
<div class="container">
<img class="myRegularImg" src="http://data.whicdn.com/images/10274608/large.jpg" style='position: absolute; width:100%; left:0px;' />
<div class="row" style="position:relative">
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
<div class="col-lg-12">
SOME CONTENT
</div>
</div>
</div>
</body>
</html>