Heim  >  Artikel  >  Web-Frontend  >  css设置背景图片和背景颜色都不显示_html/css_WEB-ITnose

css设置背景图片和背景颜色都不显示_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:12:432344Durchsuche

html Body中的代码:


    医院介绍|
    医院环境|
    美容设备|
    文化活动|
    新闻动态|
    专家介绍|
    整形博客|
    联系我们
  

css代码:

#footer{background-color:#17AEC9; height:3000px; text-align:center; width:980px; overflow:hidden;}
#footer a{color:#FFDDDF; margin:auto 10px;}

文件中总共只有这些内容,没有别的设置,背景颜色不显示。

另外,在别的文件中设置了background:url(images/head_02.jpg) no-repeat;height:400px; width:980px;背景图片无显示,div的长宽和图片的大小相同。因为在同一文件中其他的背景图片的设置可以显示,所以文件的路径应该是没错的。

期待各位高手的回答!


回复讨论(解决方案)

#footer{ background-color:#17AEC9; height:3000px; text-align:center; width:980px; overflow:hidden;}
你在这里设置了背景色,和背景图就冲突了,你要用图的话就不能用背景色!把背景色删除了!

我表示显示无误。。。

试试看把注释去掉

css注释是
/* css 注释语法 */

to:yingying901029

这段代码是只设置了背景颜色,背景图片的设置是在另外的文件中设置的。

去掉注释或者改为/* --- */后背景颜色显示正常,但是在另外的文件中我也是这样写的,有的背景图片可以显示,有的却不可以,这是为什么呢?

我这里背景色显示了,
你是不是忘记给css加上style标签了?

按以下步骤解决:
1.查看图片,把图像的像素缩小到380px,960px;刷新测试。
2.有图片的时候背景颜色不会显示。把颜色去掉。
3.如果你CSS在所在的文件夹与图片所在的文件夹是同级;把图像路径改为background:url(../images/head_02.jpg),刷新测试。
4.检查是否有其他CSS的干扰影响。
再不能发现问题,重新来建一个页面插入背景图片看看。

建议楼主把有涉及的文件都弄来看看,这样东一条西一条的看不出来

站点下有一个images的文件夹和Untitled-1.html,Untitled-2.css,index.html和index.css的文件,Untitled-1.html,Untitled-2.css中的代码如下:

  @charset "utf-8";/* CSS Document */body{width:980px; margin:0 auto; font-family:"宋体";font-size:13px; line-height:18px;}a{text-decoration:none;}.aHover a:hover{color:#00A9B3;}.clear{clear:both;}.center{text-align:center;}img{border:0px;} ul{padding:0;}/*经典项目*/.best{background:url(images/best.jpg) no-repeat; width:262px; height:350px; padding-top:20px;}.best a{color:#626262;}.best ul{ height:20px; }.best ul li{float:left; width:130px; text-align:center;list-style:none; }


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><link rel="stylesheet" type="text/css" href="Untitled-2.css"/></head><body><!--经典项目-->  <div class="best">    <ul style="margin-top:70px;">      <li><a href="#">数字2C无缝丰胸</a></li>      <li><a href="#">鼻部综合整形</a></li>    </ul>    <ul style="margin-top:52px;">      <li><a href="#">美肤OPT王者风范</a></li>      <li><a href="#">除皱 3+全效除皱</a></li>    </ul>    <ul style="margin-top:50px;">      <li><a href="#"> 韩式改脸型</a></li>      <li><a href="#">眼部综合整形</a></li>    </ul>    <ul style="margin-top:58px;">      <li><a href="#">360度环状立体吸脂</a></li>      <li><a href="#">专利微创瘦小腿</a></li>    </ul>  </div><!--class="best"--></body></html>

这样显示正常,但是我将它分别复制到index.html和index.css文件中后不能显示背景图片。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><link rel="stylesheet" type="text/css" href="index.css"/></head><body>  <img  src="images/head_01.jpg" / alt="css设置背景图片和背景颜色都不显示_html/css_WEB-ITnose" >      <div class="banner"><img  src="images/banner.jpg" / alt="css设置背景图片和背景颜色都不显示_html/css_WEB-ITnose" ></div>  <!--flash新闻-->  <div class="flash">    <div class="flashHead">    </div><!--class="flashHead"-->      <div class="flashCont">      <img  src="images/flashNews_04.jpg" / alt="css设置背景图片和背景颜色都不显示_html/css_WEB-ITnose" >    </div><!--class="flashCont"-->     <div class="flashBottom">    </div>  </div>      <!--经典项目-->  <div class="best">    <ul   style="max-width:90%">      <li><a href="#">数字2C无缝丰胸</a></li>      <li><a href="#">鼻部综合整形</a></li>    </ul>    <ul style="margin-top:52px;">      <li><a href="#">美肤OPT王者风范</a></li>      <li><a href="#">除皱 3+全效除皱</a></li>    </ul>    <ul style="margin-top:50px;">      <li><a href="#"> 韩式改脸型</a></li>      <li><a href="#">眼部综合整形</a></li>    </ul>    <ul style="margin-top:58px;">      <li><a href="#">360度环状立体吸脂</a></li>      <li><a href="#">专利微创瘦小腿</a></li>    </ul>  </div><!--class="best"--></body></html>[code=CSS]@charset "utf-8";/* CSS Document */body{width:980px; margin:0 auto; font-family:"宋体";font-size:13px; line-height:18px;}a{text-decoration:none;}.aHover a:hover{color:#00A9B3;}.clear{clear:both;}.center{text-align:center;}img{border:0px;} ul{padding:0;}/*flash新闻*/.flash{width:275px; height:350px; float:left;}.flashHead{background:url(images/flashNews_01.jpg) no-repeat; height:4px;}.flashCont{background:url(images/flashNews_08.jpg) repeat-y; height:auto; padding:3px;}.flashBottom{background:url(images/flashNews_09.jpg) no-repeat; height:5px;}.flashCont img{width: 266px; height:340px;}/*经典项目*/.best{background:url(images/best.jpg) no-repeat; width:262px; height:350px; padding-top:20px;}.best a{color:#626262;}.best ul{ height:20px; }.best ul li{float:left; width:130px; text-align:center;list-style:none; }

[/code]

不知楼主是不是犯了最低级的错误,按你所说的两部分,这样是完全没问题的.

<style>#footer{background-color:#17AEC9; height:3000px; text-align:center; width:980px; overflow:hidden;}#footer a{color:#FFDDDF; margin:auto 10px;}</style><div id="footer">  <a href="#">医院介绍</a>|  <a href="#">医院环境</a>|  <a href="#">美容设备</a>|  <a href="#">文化活动</a>|  <a href="#">新闻动态</a>|  <a href="#">专家介绍</a>|  <a href="#">整形博客</a>|  <a href="#">联系我们</a>  </div>

楼主后面给的代码,能不能只筛选相关的部分,不要全列出来,看着眼晕.

后面给的代码是筛选了的,前两个是没有问题的,后面的那两个因为里面还有其他div,所以背景图片没有显示出来。排列也有些问题,麻烦各位高手给看看。

我也纠结这个问题~~

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn