You can control the scrolling behavior of an image background using the background-attachment
and background-position
properties.
The background-attachment
property determines whether the background image scrolls with the content or is fixed in place. The options for this property are:
scroll
: the background image scrolls with the contentfixed
: the background image remains fixed in place even as the content is scrolled
The background-repeat
property determines whether the background image should repeat horizontally, vertically, or not at all. The options for this property are:
repeat-x
: the image is repeated horizontallyrepeat-y
: the image is repeated verticallyno-repeat
: the image is not repeated at all.
By using these properties, you can control how an image background behaves when the content is scrolled, and how it is positioned within its container.
<!DOCTYPE html>
<html>
<head><title>Title</title></head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<body>
<!-- Have A LOT of these -->
<h1>Some Content - Something More</h1>
<h1>Some Content - Something More</h1>
<h1>Some Content - Something More</h1>
<h1>Some Content - Something More</h1>
<h1>Some Content - Something More</h1>
<h1>Some Content - Something More</h1>
</body>
</html>
The <body> section contains a series of six <h1> tags, which are used to create headings on the page. The content inside the <h1> tags is "Some Content - Something More" and is repeated six times. This is just an example of how to include headings in a web page using HTML.
body {
background-image: url("trol.jpg");
background-repeat: no-repeat;
background-attachment: scroll;
background-position: left top;
}
The background-repeat
property is set to no-repeat
, which means the image will not repeat itself in the background.
The background-attachment
property is set to scroll
, which means the background image will scroll along with the content when the user scrolls down or up the web page.
The background-position
property is set to left top
, which positions the top left corner of the background image at the top left corner of the body element.
This CSS code will apply a fixed background image to the body element, with the image positioned at the top left corner, and the image will scroll along with the content.
No comments:
Post a Comment