html div背景图片不显示 [英] html div background image not showing up
本文介绍了html div背景图片不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理一个网页(我当然是一个新手),背景图片不会显示在div。我尝试了背景图像和背景,他们都不会工作...亲爱的代码
I'm working on a webpage (I'm a newb of course) and the background image won't show up in the div. I tried both background-image and background and they both will not work... heres the code
如果任何人都可以帮助那将是伟大的!
if anyone can help that would be great!!
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {background-color:gray;}
</style>
</head>
<body>
<div style="background-image: url('/ximages/websiteheader1.png');height:200px;width:1200px;">
</div>
</body>
</html>
推荐答案
我建议从内联作用域移动css。
假设您的.png文件实际存在,请尝试设置背景大小并重复标记。
I recommend moving your css from the inline scope. Assuming that your .png file actually exists, try setting the background size and repeat tags.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {background-color:gray;}
#mydiv {
background-image: url('/ximages/websiteheader1.png');
background-repeat:no-repeat;
background-size:contain;
height:200px;width:1200px;
}
</style>
</head>
<body>
<div id="mydiv">
</div>
</body>
</html>
如果这不起作用,请尝试在浏览器的开发人员工具中检查响应代码,并确保
If that doesn't work, try checking in your browser's developer tools for the response codes and making sure that the url is correct.
希望这有助于!
这篇关于html div背景图片不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文