Web全栈-背景颜色、背景图片、背景平铺属性、背景图片定位属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景颜色</title>
<style>
div{
width: 500px;
height: 500px;
}
.box1{
background-color: red;
}
.box2{
background-color: rgb(0,255,0);
}
.box3{
background-color: rgba(0,0,255,0.7);
}
.box4{
background-color: #0ff;
}
</style>
</head>
<body>
<!--
1.如何设置标签的背景颜色?
在CSS中有一个background-color:属性, 就是专门用来设置标签的背景颜色的
取值:
具体单词
rgb
rgba
十六进制
快捷键:
bc background-color: #fff;
-->
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景图片</title>
<style>
div{
width: 500px;
height: 500px;
}
.box1{
background-image: url(images/girl.jpg);
/*background-image: url(http://img4.imgtn.bdimg.com/it/u=2278032206,4196312526&fm=21&gp=0.jpg);*/
}
</style>
</head>
<body>
<!--
1.如何设置背景图片?
在CSS中有一个叫做background-image: url();的属性, 就是专门用于设置背景图片的
快捷键:
bi background-image: url();
注意点:
1.图片的地址必须放在url()中, 图片的地址可以是本地的地址, 也可以是网络的地址
2.如果图片的大小没有标签的大小大, 那么会自动在水平和垂直方向平铺来填充
3.如果网页上出现了图片, 那么浏览器会再次发送请求获取图片
-->
<div class="box1"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景平铺属性</title>
<style>
/*
div{
width: 500px;
height: 500px;
}
.box1{
background-image: url(images/girl.jpg);
background-repeat: repeat-y;
}
*/
/*
body{
background-image: url(images/bg2.jpg);
}
*/
div{
width: 980px;
height: 60px;
background-image: url(images/1.png);
}
</style>
</head>
<body>
<!--
1.如何控制背景图片的平铺方式?
在CSS中有一个background-repeat属性, 就是专门用于控制背景图片的平铺方式的
取值:
repeat 默认, 在水平和垂直都需要平铺
no-repeat 在水平和垂直都不需要平铺
repeat-x 只在水平方向平铺
repeat-y 只在垂直方向平铺
快捷键
bgr background-repeat:
应用场景:
可以通过背景图片的平铺来降低图片的大小, 提升网页的访问速度
-->
<div class="box1"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景图片定位属性</title>
<style>
div{
/*width: 500px;*/
height: 500px;
}
.box1{
/*background-color: red;*/
/*background-image: url(images/girl.jpg);*/
/*background-repeat: no-repeat;*/
/*background-position: left top;*/
/*background-position: right top;*/
/*background-position: right bottom;*/
/*background-position: left bottom;*/
/*background-position: center center;*/
/*background-position: left center;*/
/*background-position: center top;*/
/*background-position: 100px 0;*/
/*background-position: 100px 200px;*/
/*background-position: -100px -100px;*/
background-image: url(images/yxlm.jpg);
background-position: center top;
}
</style>
</head>
<body>
<!--
1.如何控制背景图片的位置?
在CSS中有一个叫做background-position:属性, 就是专门用于控制背景图片的位置
2.格式:
background-position: 水平方向 垂直方向;
3.取值
2.1具体的方位名词
水平方向: left center right
垂直方向: top center bottom
2.2具体的像素
例如: background-position: 100px 200px;
记住一定要写单位, 也就是一定要写px
记住具体的像素是可以接收负数的
快捷键:
bp background-position: 0 0;
注意点:
同一个标签可以同时设置背景颜色和背景图片, 如果颜色和图片同时存在, 那么图片会覆盖颜色
-->
<div class="box1">
<!--<img src="images/yxlm.jpg" alt="">-->
</div>
</body>
</html>
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
author:yindanny
email: yindanny@qq.com
github: https://github.com/yindanny
githubblog: https://yindanny.github.io