Forked from conor-egan/Responsive fixed background image
Last active
January 4, 2016 12:19
-
-
Save csknk/8621282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*HTML Structure looks like this*/ | |
<Body> | |
<img src = "http://conoregan.com/wp-content/uploads/2014/01/2013-12-04-08.50.18.jpg" class="background"> | |
<div class="wrapper"> | |
<p>The quick brown fox jumps over the lazy dog</p> | |
</div> | |
<style> | |
img.background { | |
/* Set rules to fill background */ | |
min-height: 100%; | |
min-width: 1024px; | |
/* Set up proportionate scaling */ | |
width: 100%; | |
height: auto; | |
/* Set up positioning */ | |
position: fixed; | |
top: 0; | |
left: 0; | |
} | |
@media screen and (max-width: 1024px) { /* Specific to this particular image */ | |
img.background { | |
left: 50%; | |
margin-left: -512px; /* 50% */ | |
} | |
} | |
/*all content on page must be in a wrapper that has position:relative*/ | |
.wrapper{ | |
position:relative | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment