背景图片不会显示在CSS中,除非我使用< img>标记 [英] Background Image won't show up in CSS unless I load an image using the <img> tag in HTML

查看:93
本文介绍了背景图片不会显示在CSS中,除非我使用< img>标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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> 

只有一小部分的图像与文字一起显示...我很困惑为什么会发生这种情况。我可以显示整个图像的唯一方法是如果我在图像周围添加几乎170px的填充。有人请帮忙!

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!

感谢。

推荐答案


  1. < / style>

  2. #pic 的宽度和高度为零,因此背景不会显示。

  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.

检查它是否正常工作,这里: http://jsfiddle.net/UzcDM/1/

Check it out working, here: http://jsfiddle.net/UzcDM/1/

这篇关于背景图片不会显示在CSS中,除非我使用&lt; img&gt;标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆