I am trying to do the following...
- Have an image that will always be horizontally and vertically centered on a page, whatever the screen size.
- Maintain aspect ratio on resize
- Have some text that will always be at the bottom of the viewport.
I have come up with two half solutions so far...
I am looking for a solution that combines both the above. Here is my code if you can't click the links above...
HTML
<div class="image">
<div class="wrap">
<img src="http://upload.wikimedia.org/wikipedia/commons/3/36/Hopetoun_falls.jpg">
</div>
</div>
<div class="text">Scroll down</div>
CSS
//Solution 1
html, body {height: 100%}
body {
position: relative;
padding: 0;
margin:0;
font-family: sans-serif;
}
.image {
position: relative;
left: 0px;
height: 100%;
background-position: 50% 50%;
background-size: cover;
background-attachment: scroll;
text-align: center;
}
img {
width: 70%;
height: 70%;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
.text {
margin-top: -50px;
text-align: center;
}
// Solution 2 - same as above but with .wrap class
.wrap {
overflow: hidden;
position: relative;
padding-top: 65%;
}
Any help would be greatly appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…