Home >Web Front-end >CSS Tutorial >Detailed explanation of the use of CSS background-attachment

Detailed explanation of the use of CSS background-attachment

php中世界最好的语言
php中世界最好的语言Original
2018-03-22 10:08:423147browse

This time I bring to you, what are the precautions, the following is a practical case, let's take a look.

1. background-attachmentAttribute

In CSS, use the background attachment attribute background-attachment to set the background imageWhether it scrolls with the object or remains fixed.
Syntax:
background-attachment:scroll/fixed;
Description:
The background-attachment attribute has only 2 attribute values. scroll means that the background image scrolls as the object scrolls, which is the default option; fixed means that the background image is fixed on the page, and only other content scrolls with the scroll bar.

Example:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        #p1
        {
            width:160px;
            height:1200px;
            border:1px solid gray;
            background-image:url("cartoongirl.gif");
            background-repeat:no-repeat;
            background-attachment:fixed;
        }
    </style>
</head>
<body>
    <p id="p1"></p>
</body>
</html>

The preview effect in the browser is as follows:

I believe you have mastered the method after reading the case in this article, more Please pay attention to other related articles on the php Chinese website!

Recommended reading:

There are several ways to implement three-column layout in CSS

CSS and Sass development specifications

CSS to make the icon rotate when the mouse moves up

The above is the detailed content of Detailed explanation of the use of CSS background-attachment. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn