首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >背景图像重复,即使使用“Background -repeat:no-repeat”

背景图像重复,即使使用“Background -repeat:no-repeat”
EN

Stack Overflow用户
提问于 2011-12-30 18:12:03
回答 5查看 71.8K关注 0票数 5

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

代码语言:javascript
复制
<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>    
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-12-30 19:00:12

你已经有很多的答案告诉你如何解决重复的图像问题,但是如果你决定使用CSS设计,这里有一些东西可以让你入门。这将消除对图像的需求。您将使用更少的HTML,并且它更具可配置性。

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

HTML:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
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;
}

输出:

票数 5
EN

Stack Overflow用户

发布于 2011-12-30 18:14:40

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

代码语言:javascript
复制
<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>
票数 5
EN

Stack Overflow用户

发布于 2011-12-30 18:14:01

在我看来像是打字错误。你有没有试过用style="background-repeat: no-repeat"替换background-repeat: no-repeat

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

您需要在<table>标记中放入一个id="menu",然后将其放入head中的某个位置

代码语言:javascript
复制
<style>
#menu td {
    background-position: center center;
    background-repeat: no-repeat;
}
</style>

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8678370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档