除非我使用 加载图像,否则背景图像不会显示在 CSS 中。 HTML 中的标签

发布于 2024-10-10 15:59:25 字数 346 浏览 0 评论 0原文

我非常困惑为什么我的代码无法正确显示图像。这是我的代码:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若相惜即相离 2024-10-17 15:59:25
  1. #pic 的宽度和高度为零之前,您需要一个右大括号,因此背景不会显示。将内容放入 div 中,或设置宽度和高度。

检查它的工作情况,在这里:http://jsfiddle.net/UzcDM/1/

  1. You need a closing brace before </style>
  2. #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/

追风人 2024-10-17 15:59:25

您需要指定 div 的宽度和高度。

另外,请确保关闭 CSS:

#pic {
   background:url('http://www.tishbi.eu/img/shopping_cart.png') no-repeat;
   width: 200px;
   height: 300px;
}

You need to specify a width and height for your div.

Also, make sure you close your CSS:

#pic {
   background:url('http://www.tishbi.eu/img/shopping_cart.png') no-repeat;
   width: 200px;
   height: 300px;
}
摇划花蜜的午后 2024-10-17 15:59:25

将高度和宽度放入您的 css 类中。

请在此处查看演示

Put Height and width in your css class.

Please view demo here

病毒体 2024-10-17 15:59:25

采取正确的路径设置,例如../../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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文