Skip to content

Instantly share code, notes, and snippets.

@conor-egan
Last active January 3, 2016 21:59
Show Gist options
  • Save conor-egan/8525368 to your computer and use it in GitHub Desktop.
Save conor-egan/8525368 to your computer and use it in GitHub Desktop.
Responsive fixed background image
<Body>
<img src ="http://conoregan.com/wp-content/uploads/2014/01/2013-12-04-08.50.18.jpg" class="background">
<div class="wrapper">
<p>Page content</p>
</div>
</body>
//CSS:
.wrapper{
position:relative
}
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% */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment