我们在进行网页布局设计的时候,往往需要使用图片来美化页面,那么如何在CSS中正确地写入图片位置呢?首先,在HTML中引入图片的方式有很多种,如使用img标签或者背景图片等。其中,我们在使用背景图片作为...
我们在进行网页布局设计的时候,往往需要使用图片来美化页面,那么如何在CSS中正确地写入图片位置呢?
首先,在HTML中引入图片的方式有很多种,如使用img标签或者背景图片等。其中,我们在使用背景图片作为页面元素时,就需要借助CSS来设置。
举个例子,我们希望设置某个div元素的背景图片为“example.png”,并让其显示在元素的左上角。那么在CSS中,我们可以这样写:
.para1 {
background-image: url('example.png');
background-position: left top;
} .para2 {
background-image: url('example.png');
background-position: center;
} .para3 {
background-image: url('example.png');
background-repeat: no-repeat;
} .para4 {
background-image: url('example.png');
background-size: cover;
}