简体   繁体   English

CSS背景不起作用

[英]CSS Background doesn't work

I have a problem. 我有个问题。 I try to add background to a table cell but doesn't work. 我尝试向表格单元格添加背景,但是不起作用。

.price-table td.left-up {
    background: url("img/left-up.png") no-repeat;
    width: 181px;
    height: 118px;
}

and HTML: 和HTML:

<div class="price-table">
  <table>
    <tr>
      <td class="left-up">
        sdst
      </td>
    </tr>
  </table>
</div>

You have specified a relative path name here - which is probably why the image isn't loading. 您在此处指定了相对路径名-这可能就是为什么图像未加载的原因。 Remember that relative paths work relative to the CSS file, not to the page. 请记住,相对路径相对于CSS文件而不是页面有效。 For example: 例如:

/site
  -page.htm
  /css
    -site.css
  /img
    -left-up.png

If this were your folder structure you would need: 如果这是您的文件夹结构,则需要:

background: url("../img/left-up.png") no-repeat;

This is because the image is one level up relative to the css file . 这是因为图像相对于css文件是上一级的。 Hope that helps you figure out the correct path! 希望能帮助您找出正确的路径!

Use a pure link to your image eg. 使用纯链接到您的图片,例如。 http://yoursite.com/img/left-up.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM