div怎么设置背景图片?

div怎么设置背景图片?,第1张

1、首先我们打开sublimetext软件,新建一个html页面,然后在在页面中添加html的基本结构;

2、然后我们在html的body区域添加一个div,并且给div设置一下宽高以及边框的样式;

3、运行程序以后,你就会看到的div区域,我们接下来就要给这个区域添加背景图片;

4、然后我们回到html文档,在div的样式规则里面添加background-image属性,给此属性指定一个图片路径,运行以后你就会看到背景图片了。

<div style="background-color:red">

</div>

具体如下:

样式标签属性 样式属性(用在js等脚本中)

background background 设置或获取对象最多五个独立的背景属性。

background-attachment backgroundAttachment 设置或获取背景图像如何附加到文档内的对象中。

background-color backgroundColor 设置或获取对象内容后的颜色。

background-image backgroundImage 设置或获取对象的背景图像。

background-position backgroundPosition 设置或获取对象背景的位置。

background-position-x backgroundPositionX 设置或获取 backgroundPosition 属性的 x 坐标。

background-position-y backgroundPositionY 设置或获取 backgroundPosition 属性的 y 坐标。

background-repeat backgroundRepeat 设置或获取对象的 backgroundImage 属性如何平铺。

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html,填写问题基础代码。

2、在index.html中的<script>标签,输入js代码:$('div').css('background-color', 'blue')。

3、浏览器运行index.html页面,此时div的背景颜色被js动态修改为了蓝色。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11836500.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存