part tow images tag chapter 10
PART TOW HTML IMAGE TAG
Background Image on a HTML element
To add a background image on an HTML element, you can use
the
style
attribute:
<!DOCTYPE html>
<html>
<body>
<h2>Background Image</h2>
<div style="background-image: url('temp.jpg');">
You can specify background images<br>
for any visible HTML element.<br>
In this example, the background image<br>
is specified for a div element.<br>
By default, the background-image<br>
will repeat itself in the direction(s)<br>
where it is smaller than the element<br>
where it is specified. (Try resizing the<br>
browser window to see how the<br>
background image behaves.
</div>
</body>
</html>
OUTPUT
Background Image
You can specify background images
for any visible HTML element.
In this example, the background image
is specified for a div element.
By default, the background-image
will repeat itself in the direction(s)
where it is smaller than the element
where it is specified. (Try resizing the
browser window to see how the
background image behaves.
for any visible HTML element.
In this example, the background image
is specified for a div element.
By default, the background-image
will repeat itself in the direction(s)
where it is smaller than the element
where it is specified. (Try resizing the
browser window to see how the
background image behaves.
You can also
specify the background image in the
<style>
element:
<!DOCTYPE
html>
<html>
<style>
div {
background-image: url('temp.jpg');
}
</style>
<body>
<h2>Background
Image</h2>
<div>
You can specify
background images<br>
for any visible
HTML element.<br>
In this example,
the background image<br>
is specified for
a div element.<br>
By default, the
background-image<br>
will repeat
itself in the direction(s)<br>
where it is
smaller than the element<br>
where it is
specified. (Try resizing the<br>
browser window
to see how the<br>
background image
behaves.
</div>
</body>
</html>
Background
Image on a Page
If you want the entire page to
have a background image, then you must specify the background image on
the <body>
element:
<!DOCTYPE html>
<html>
<style>
body {
background-image: url('temp.jpg');
}
</style>
<body>
<h2>Background
Image</h2>
<p>By default
the background image will repeat itself if it is smaller than the element where
it is specified, in this case the BODY element.</p>
</body>
</htm
Background
Repeat
If the background image is
smaller than the element, the image will repeat itself, horizontally and
vertically, until it reaches the end of the element:
<!DOCTYPE html>
<html>
<style>
body {
background-image: url('temp.jpg');
}
</style>
<body>
<h2>Background Repeat</h2>
<p>By default the background image will
repeat itself if it is smaller than the element where it is specified, in this
case the BODY element.</p>
</body>
</html>
To avoid the background
image from repeating itself, use the
background-repeat
property.
<!DOCTYPE html>
<html>
<style>
body {
background-image: url('temp.jpg');
background-repeat: no-repeat;
}
</style>
<body>
<h2>Background No Repeat</h2>
<p>You can avoid the image from being
repeated by setting the background-repeat property to
"no-repeat".</p>
</body>
</html>
Background
Cover
If you want the background image cover the entire element, you can
set the
background-size
property
to cover.
Also, to make sure the entire element is always covered, set
the
background-attachment
property
to fixed: