Skip to content

Instantly share code, notes, and snippets.

@kdipietro kdipietro/index.html
Created Apr 14, 2013

Embed
What would you like to do?
A CodePen by kdipietro. CSS Backgrounds Example
<!--YOU MAY ADJUST THE CODE FOR YOUR OWN TINKERING KNOWLEDGE, BUT DO NOT CLICK SAVE! -->
<body>
<h1>CSS Backgrounds</h1>
<p id="p1">This is an example of background image positioning with CSS.</p>
<p id="p1">What we have done here is linked to a background image from an image hosting site, and told the webpage how to position the image.</p>
<p id="p1">Notice that as we scroll down, the background image stays fixed in position, because of the "background-attachment" attribute.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p id="p1">End.</p>
</body>
/* YOU MAY ADJUST THE CODE FOR YOUR OWN TINKERING KNOWLEDGE, BUT DO NOT CLICK SAVE */
h1{
font-family: Futura;
color: red;
text-decoration: underline;
}
#p1{
font-family: Futura;
color: dark-grey;
}
body{
background-image:url('http://i.imgur.com/UzlGbpr.jpg');
background-repeat:no-repeat;
background-position:right bottom;
background-attachment: fixed;
background-size: 500px;
}
/* By default, the HTML document uses the "scroll" value for the "background-attachment" attribute. This means that the background image will scroll along the page.
The image that we've referenced is native sized at 720px x 888px. Notice that we can use the "background-size" attribute to resize the image. You can add two values to resize the image (x,y), but in this case we've only added the width (x) size that we want and the height (x) size will be scaled down uniformly. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.