html中background- attachment
时间: 2023-05-03 20:02:12 浏览: 69
background-attachment在HTML中是用来设置背景图片是否固定或随滚动条滚动的属性。可以设置值为fixed(固定不动)、scroll(随滚动条滚动)、local(背景图像随着元素移动)或者inherit(继承父元素)等。
相关问题
css的background-attachment的属性及演示
background-attachment属性指定背景图像是否固定或随着页面滚动而移动。它有以下几个值:
1. scroll(默认值):背景图像随着页面滚动而移动。
2. fixed:背景图像固定不动,不随着页面滚动而移动。
3. local:背景图像相对于元素内容固定,不随着页面滚动而移动。
以下是演示:
```html
<!DOCTYPE html>
<html>
<head>
<title>Background Attachment Demo</title>
<style type="text/css">
body {
height: 2000px;
}
.bg-scroll {
background-image: url('https://picsum.photos/1200/800');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: scroll;
}
.bg-fixed {
background-image: url('https://picsum.photos/1200/800');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
.bg-local {
background-image: url('https://picsum.photos/1200/800');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: local;
height: 500px;
overflow: scroll;
}
.content {
padding: 50px;
color: #fff;
text-align: center;
font-size: 2em;
}
</style>
</head>
<body>
<div class="bg-scroll">
<div class="content">
Scroll Background
</div>
</div>
<div class="bg-fixed">
<div class="content">
Fixed Background
</div>
</div>
<div class="bg-local">
<div class="content">
Local Background
</div>
</div>
</body>
</html>
```
以上代码将创建三个不同的元素,每个元素都有不同的background-attachment属性。第一个元素的背景图像随着页面滚动而移动,第二个元素的背景图像固定不动,第三个元素的背景图像相对于元素内容固定,只有元素内容区域内可以滚动。
html5中background-cut是干什么用的
在 HTML5 中,background-clip 属性定义了元素的背景是否延伸到边框下面。而 background-clip 属性则决定了背景的剪切方式。
具体来说,background-clip 属性用于指定背景的剪切区域,可以取以下值:
- border-box:背景被剪切到边框盒子的边缘。这是默认值。
- padding-box:背景被剪切到内边距框的边缘。
- content-box:背景被剪切到内容框的边缘。
- text:背景被剪切到文本的前景色所在的区域。这个值只有在 background-color 属性和 background-attachment 属性都设置为默认值时才有效。
而 background-clip 属性的补充属性 background-origin 指定了背景图片的位置区域,可以取以下值:
- border-box:背景图片从边框盒子的边缘开始显示。这是默认值。
- padding-box:背景图片从内边距框的边缘开始显示。
- content-box:背景图片从内容框的边缘开始显示。
最后,background-cut 属性是 background-clip 和 background-origin 两个属性的缩写形式,可以同时指定这两个属性的值。例如:
div {
background-cut: padding-box content-box;
}
这个例子中,背景的剪切区域为 padding-box,背景图片的位置区域为 content-box。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<!DOCTYPE html> <html> <head> <title>登录界面</title> <meta charset="utf-8" /> <title></title> </head> <style> input[type="text"], input[type="password"] { display: block; width: 5%; padding: 10px; margin-bottom: 20px; border-radius: 5px; border: 1px solid #ccc; font-size: 1.2em; } body{ background: url(image/java.jpg) top left; width: 10240px; height: 5120px; background-attachment: fixed; background-repeat: no-repeat; background-size: 100%; } 00 input[type="submit"] { background-color: Transparent; color: #abc1ee; padding: 10px 20px; border-radius: 5px; border: none; font-size: 1.2em; cursor: pointer; } a { text-decoration-line: none; color: #abc1ee; } </style> <body> Welcome to Login Login <input type="text" name="username" placeholder="username" > <input type="password" name="password" placeholder="password" > <input type="submit" value="Login"> Don't have account? Sign up </body> </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)