Skip to main content

CSS3 Responsive Website Background Tutorial

For a better understanding of the results you can achieve by styling your website background I will demonstrate the options you have using CSS3.

 

The background-image property displays one or more background images for an element. In this tutorial we will cover using one background image to style the background of the HTML body.





We will use the image above as background-image and regent st blue (#9abee1) as background-color.



The correct CSS syntax for the HTML body background image & color is:


body{
background-image:url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijRO0KKRuzG_5fiiucDOYAIk7X4H20Lz8q9iMSn5ZZ9Yj6iATQd5_7Zwezg8eVQ_qgDpfJW6qGuBO45ZHPOn6Whar0x1lCJvRHDr-GOdNjTizk_oVvRiwXCxjh2cUT3qKHjljPTQyxGjM/s1600/bg.jpg');
background-color:#9abee1;
}


However, using only this code the image will be tiled (in most browsers), and not stretched to cover the entire browser window.




We will now make sure the background image does not scroll with the page by using the background-attachment property.

Also, we will center the image vertically and horizontally by using the background-position property, and stretch the background image to cover the entire background by using the background-size property.

You code should now look like this:


body{
background-image:url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijRO0KKRuzG_5fiiucDOYAIk7X4H20Lz8q9iMSn5ZZ9Yj6iATQd5_7Zwezg8eVQ_qgDpfJW6qGuBO45ZHPOn6Whar0x1lCJvRHDr-GOdNjTizk_oVvRiwXCxjh2cUT3qKHjljPTQyxGjM/s1600/bg.jpg');
background-color:#9abee1;
background-attachment:fixed;
background-position:center center;
background-size:cover;
}


And the end result should look like this:



And here is the same page at a different resolution:


 

Please leave your comments and/or questions in the comments section below.

Comments

Popular posts from this blog

iPhone 5 Rumor Roundup

Release Date The latest rumors regarding the iPhone 5 indicate that the official release date will be officially announced during the next Apple event which is to be held on September 12th 2012. According to Verizon CFO, Fran Shammo, Apple (AAPL) will stick to last year's release date and launch the iPhone 5 in October 2012. Although during the 2012 WWDC we had the opportunity to get some more details about iOS 6, no hardware specifications were released. source - 9to5mac.com Larger Screen The iPhone 5 is rumoured to have a larger, 4 inch retina display. source - Apple.pro Nano SIM According to the Financial Times, mobile carriers in Europe are stocking up on Nano SIM cards. This might be related to the release of the next generation iPhone. Smaller Dock Connector Another wide spread rumour is that Apple will release the iPhone 5 with a smaller, 8 pin dock connector. This means that new cables will be available for  new Apple devices released in the future. Did you hear any new rum...

Single Page HTML5 CSS3 Business Card Template 2.0

After seeing a huge interest in the Single Page Business Card Tutorial  i decided to create a Single Page Business Card 2.0 Template. Besides listing your title and contact details the 2.0 template also has some nice CSS3 transition effects, is available in 4 colors and the best part: IT'S FREE FOR DOWNLOAD . Demo Download CSS3 Transition Effect On hover the Name/Title block and the Contact Details blocks slide out vertically showing a centered block containing name and position, social and contact icons. Red Template Demo Blue Template Demo Yellow Template Demo Green Template Demo

HTML Codes for Romanian Characters

Character Simple Code Numerical Code Hex Code Ă Ă Ă ă ă ă Â Â Â Â â â â â Î Î Î Î î î î î Ș Ș Ú ș ș Û Ş Ş Ş ş ş ş Ţ Ţ Ţ ţ ţ ţ