关于背景图片的问题
来源:7-2 编程练习
TryMyBestToDo
2020-08-14 18:41:18
老师,请问这里为什么我设置main宽度为100%后背景图片就不行了;
把main去掉就成功了
还有就是怎样把背景图片直接设置在main的css里而不用再html里加一个<img>?
我试过background-image:url("");但没成功
5回答
好帮手慕小脸
2020-08-15
同学你好,直接将图片设置为背景图片可以使用
background-image:url(http://climg.mukewang.com/59c9f7ce0001839219034033.png);
这里是直接给body设置背景图片,紧接着调整宽高,图片大小,以及其他样式,如:
body{ background-image:url(http://climg.mukewang.com/59c9f7ce0001839219034033.png); width:1200px; height:2000px; background-size:1200px 2000px; background-position: center center; background-repeat: no-repeat; margin:0px 0px 0px 0px; }
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
TryMyBestToDo
提问者
2020-08-15
<!DOCTYPE html>
<html>
<head>
<title>广告</title>
<link rel="stylesheet" type="text/css" href="index.css"/>
</head>
<body>
<div id="main">
<!-- <img src="http://climg.mukewang.com/59c9f7ce0001839219034033.png" alt="没找到" id="backgroundImage"> -->
<div id="advertising1"><img src="http://climg.mukewang.com/5a3383c70001f1b702240364.png" alt="没找到" class="inside"></div>
<div id="advertising2"><img src="http://climg.mukewang.com/5a3383d00001a3dd02240364.png" alt="没找到" class="inside"></div>
</div>
</body>
</html>
#main{
width: 100%;
height: 100%;
background-image: url("http://climg.mukewang.com/59c9f7ce0001839219034033.png");
background-size: 1200px 2000px;
}
/*#backgroundImage{
width: 100%;
}*/
#advertising1{
position: fixed;
top: 50%;
margin-top: -200px;
}
#advertising2{
position: fixed;
width: 300px;
height: 400px;
top: 50%;
right: 0px;
margin-top: -200px;
}
.inside{
width: 300px;
height: 400px;
}
请问有什么方法能够直接设置背景图片?
好帮手慕小脸
2020-08-14
同学你好,建议同学将代码贴出,方便老师测试运行。
祝学习愉快~
TryMyBestToDo
提问者
2020-08-14
后来我尝试设置背景图片大小:
TryMyBestToDo
提问者
2020-08-14
就像这样:
相似问题