HTML and CSS Background
Written on July 27, 2007 by admin
In this tutorials, you will learn how to set the background color with CSS.
How to set background color
HTML:
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<title>this is the title of the web page</title>
-
-
<style type="text/css">
-
body {background-color: yellow;}
-
h1 {background-color: #00ff00;}
-
h2 {background-color: red;}
-
p {background-color: rgb(250,0,255);}
-
</style>
-
-
</head>
-
This is a level 1 header
-
</h1>
-
This is a level 2 header
-
</h2>
-
This is a paragraph
-
</p>
-
</body>
-
</html>
How to set an image as the background
HTML:
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<title>this is the title of the web page</title>
-
-
<style type="text/css">
-
-
body
-
{
-
background-image:
-
url('csshtmltutorial-image.jpg')
-
}
-
-
</style>
-
-
</head>
-
</body>
-
</html>
How to repeat a background image
HTML:
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<title>this is the title of the web page</title>
-
-
<style type="text/css">
-
-
body
-
{
-
background-image:
-
url('csshtmltutorial.jpg');
-
background-repeat: repeat;
-
}
-
-
</style>
-
-
</head>
-
</body>
-
</html>
How to repeat an image vertically only
HTML:
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<title>this is the title of the web page</title>
-
-
<style type="text/css">
-
-
body
-
{
-
background-image:
-
url('csshtmltutorial.jpg');
-
background-repeat: repeat-y;
-
}
-
-
</style>
-
-
</head>
-
</body>
-
</html>
How to repeat a background image horizontally only
HTML:
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<title>this is the title of the web page</title>
-
-
<style type="text/css">
-
-
body
-
{
-
background-image:
-
url('csshtmltutorial.jpg');
-
background-repeat: repeat-x;
-
}
-
-
</style>
-
-
</head>
-
</body>
-
</html>
How to repeat one background image at a time
HTML:
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-
<title>this is the title of the web page</title>
-
-
<style type="text/css">
-
-
body
-
{
-
background-image:
-
url('csshtmltutorial.jpg');
-
background-repeat: no-repeat;
-
}
-
-
</style>
-
-
</head>
-
</body>
-
</html>



Thanks. Been trying to find how to do this for a while now. Helpful.
cyberst0rm’s tech blog
http://cyberst0rm.blogspot.com