背景图像重复甚至与'背景重复:不重复'

时间:2011-12-30 10:12:03

标签: html css

我无法阻止td元素中的图像重复。它看起来很丑陋。我该如何解决这个问题?我也添加了background-repeat: no-repeat代码,但它仍然无效。请不要建议从%的宽度中删除td

enter image description here

<table bgcolor="#d0e9ff" width= "100%">
 <td width="9%" height="40" background="images/button.jpg" background-repeat: no-repeat>
     <div align="center" border="0"><font face="arial, verdana, san-serif" size="2" ><a href="index.html " style="text-decoration:none"> 
     <font color="#ffffff"><b>Home</a></font></div>
  </td>

  <td width="9%" height="40" background="images/button.jpg" background-repeat: no-repeat>
     <div align="center"><font face="arial, verdana, san-serif" size="2"><a href="aboutus.html" style="text-decoration:none">
     <font color="#ffffff"><b>About Us</a></font></div>
  </td>

  <td width="9%" height="40" background="images/button.jpg" background-repeat: no-repeat>
    <div align="center"><font face="arial, verdana, san-serif" size="2"><a href="T&C.html" style="text-decoration:none">
    <font color="#ffffff"><b>Training and Certifications</a></font></div>
  </td>

  <td width="9%" height="40" background="images/button.jpg" background-repeat: no-repeat>
     <div align="center"><font face="arial, verdana, san-serif" size="2"><a href="services.html" style="text-decoration:none">
     <font color="#ffffff"><b>Services</a></font></div>
   </td>

    <td width="9%" height="40" background="images/button.jpg" background-repeat: no-repeat>
     <div align="center"><font face="arial, verdana, san-serif" size="2"><a href="Contactus.html" style="text-decoration:none">
     <font color="#ffffff"><b>Contact Us</a></font></div>
   </td>
</table>    

5 个答案:

答案 0 :(得分:5)

您已经有很多答案告诉您如何解决重复图像问题,但如果您决定使用CSS设计,这里可以帮助您入门。这将消除对图像的需要。您将使用更少的HTML并且它更易于配置。

演示:http://jsfiddle.net/ThinkingStiff/fJEJf/

HTML:

<ul>
    <li><a class="a" href="index.html">Home</a></li><!--
    --><li><a class="a" href="aboutus.html">About Us</a></li><!--
    --><li><a class="a" href="T&C.html">Training</a></li><!--
    --><li><a class="a" href="services.html">Services</a></li><!--
    --><li><a class="a" href="Contactus.html">Contact Us</a></li>
</ul>

CSS:

ul {
    background-color: #d0e9ff;
    margin: 0;
    padding: 0;
    white-space: nowrap;
}

li {
    display: inline-block;   
    padding: 4px;
    width: 19.5%;
}

a {
    background-color: gray;
    border-radius: 16px;
    color: white;
    display: block;
    font: bold 13px arial, verdana, san-serif;
    height: 32px;
    line-height: 32px;
    text-align: center;
    text-decoration: none;
}

输出:

enter image description here

答案 1 :(得分:4)

您必须在background-repeat属性中设置style属性:

<td width="9%" height="40" background="images/button.jpg" style="background-repeat: no-repeat">
    <div align="center"><font face="arial, verdana, san-serif" size="2"><a href="aboutus.html" style="text-decoration:none">
    <font color="#ffffff"><b>About Us</a></font></div>
</td>

答案 2 :(得分:2)

对我而言似乎是一个错字。您是否尝试将background-repeat: no-repeat替换为style="background-repeat: no-repeat"

编辑:我看到了您的网站,正确的CSS不仅仅是这个。

您需要在id="menu"标记中添加<table>,然后将其放在head

中的某个位置
<style>
#menu td {
    background-position: center center;
    background-repeat: no-repeat;
}
</style>

另外,正如其他成员所说,您最好将图像背景放在css属性本身(实际上是自己的样式表)而不是HTML代码中。

答案 3 :(得分:0)

您可以使用:

style="background: url('images/button.jpg') top left no-repeat;"

答案 4 :(得分:0)

    <style>
     #img_center {
    background-position: center center;
    background-repeat: round;
    }
   </style>

这对我有用