除非我使用 加载图像,否则背景图像不会显示在 CSS 中。 HTML 中的标签
我非常困惑为什么我的代码无法正确显示图像。这是我的代码:
<style type = "text/css">
#pic {
background:url('http://www.tishbi.eu/img/shopping_cart.png') no-repeat;
</style>
<div id = "pic"> <p>
</p> </div>
只有图像的一小部分与文本一起显示......我很困惑为什么会发生这种情况。显示整个图像的唯一方法是在图像周围添加近 170 像素的填充。请有人帮忙!
谢谢。
I'm extremely confused why my code won't display the image properly. Here's my code:
<style type = "text/css">
#pic {
background:url('http://www.tishbi.eu/img/shopping_cart.png') no-repeat;
</style>
<div id = "pic"> <p>
</p> </div>
Only a tiny portion of the image is displayed along with the text... I'm so confused why this is happening. The only way I can display the whole image is if I add almost 170px of padding around the image. Someone please help!
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
#pic
的宽度和高度为零之前,您需要一个右大括号,因此背景不会显示。将内容放入 div 中,或设置宽度和高度。检查它的工作情况,在这里:http://jsfiddle.net/UzcDM/1/
</style>
#pic
has a width and height of zero, so the background wont show. Either put content in the div, or set a width and height.Check it out working, here: http://jsfiddle.net/UzcDM/1/
您需要指定
div
的宽度和高度。另外,请确保关闭 CSS:
You need to specify a width and height for your
div
.Also, make sure you close your CSS:
将高度和宽度放入您的 css 类中。
请在此处查看演示
Put Height and width in your css class.
Please view demo here
采取正确的路径设置,例如../../Images/logo/google.png,
尝试添加position:absolute;
它可能只是在某些元素后面
taking that path set right e.g. ../../Images/logo/google.png,
try adding position:absolute;
it might be simply behind some elements