I am trying to align two images in two divs. These are the two images, they are the same size, resolution, and the aligning is perfect when doing it in photoshop:
But when I reference them in my index.html like so:
<!-- Intro Header -->
<div class="intro">
<div class="intro-body">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h2>ssss</h1>
</div>
</div>
</div>
</div>
</div>
<!-------acerca---------->
<div id="acerca" class="acerca">
<div class="acerca-body">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h2>Acerca de Cssss</h2>
</div>
</div>
</div>
</div>
</div>
With the exact same css classes:
.intro {
display: table;
width: 100%;
height: auto;
padding: 100px 0;
text-align: center;
color: #fff;
background: url(http://i.imgur.com/jDhQ6PP.jpg?1) no-repeat bottom center scroll;
background-color: #000;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
.intro .intro-body {
display: table-cell;
vertical-align: middle;
}
.intro .intro-body .brand-heading {
font-size: 40px;
}
.intro .intro-body .intro-text {
font-size: 18px;
}
.acerca {
display: table;
width: 100%;
height: auto;
padding: 100px 0;
text-align: center;
color: #fff;
background: url(http://i.imgur.com/raMFNcc.png?1) no-repeat bottom center scroll;
background-color: #000;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
.acerca .acerca-body {
display: table-cell;
vertical-align: middle;
}
.acerca .acerca-body .brand-heading {
font-size: 40px;
}
.acerca .acerca-body .acerca-text {
font-size: 18px;
}
And the images do not align as you can see in this picture:
I can’t post images because of lacking reputation points, this is only my second question.
Do anyone know how to align them? Thanks.
JSfiddle: https://jsfiddle.net/uyo35tuf/
2
Answers
Look like you want use
Cover it is not the same
https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
I found a very useful explanation about:
http://blog.vjeux.com/2013/image/css-container-and-cover.html
And you don´t need prefix
http://shouldiprefix.com/#background-image-options
As well I propose to you a solution:
CSS
HTML
You have a example here with the proper prefixs. http://jsfiddle.net/luarmr/y33yc91z/2/
With the help of Raul’s suggestion, I played around the code and got the output as needed.
100% 100%
will make the image render as it is and responsive as well.Also replace
height: auto
withheight: 50vh
. It tells the browser to occupy 50% of the view port height. Thus it makes 100vh for the two divs.