背景图像不适用于css id,但适用于css体

时间:2013-05-23 05:27:58

标签: html5 css3 background-image relative-path

<。>在.CSS文件中:

当我申请时

body {
font-size: .85em;
font-family: "Segoe UI", Verdana, Helvetica, Sans-Serif;
color: #232323;
background-color: #fff;
background: url('Images/Login_Background.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-color: #FFFFFF;
background-position: center center;
background-size: 100% 100%;}

background-image:url('Images/Login_Background.jpg');正常工作

但是,只要我做了一个像:

#login {
background: url('Images/Login_Background.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-color: #FFFFFF;
background-position: center center;
background-size: 100px 100px;}

当我的<section id="login">使用此css ID时; background: url('Images/Login_Background.jpg');样式不起作用!!!

我错了哪个地方我无法发现?从这累了!!!

2 个答案:

答案 0 :(得分:0)

不确定您期望的结果是什么,但您无法在div中看到背景

  1. 由于background-repeat: no-repeat;属性,这是一个没有它的演示:http://jsfiddle.net/dBRQw/

  2. 元素的高度,请记住,空div的高度为0px(除非您为其指定值或其中包含内容),在这种情况下,您将无法看到背景,如:http://jsfiddle.net/dBRQw/1/

  3. 这可能会给你带来问题,因为你也使用了background-position: center center;属性,这会将你的100px大小的背景发送到该元素的中心

    http://jsfiddle.net/dBRQw/2/

    我已将div的宽度和高度设置为900px,因此您可以在中心看到背景。总结一下,你的问题可能是因为你的元素没有高度或没有内容使得他默认为0px高度。

    希望这会对你有所帮助。

答案 1 :(得分:0)

替换

#login {
background: url('Images/Login_Background.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-color: #FFFFFF;
background-position: center center;
background-size: 100px 100px;}        

#login {
background-image:url(Images/Login_Background.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-color: #FFFFFF;
background-position: center center;
background-size: 100px 100px;
}        

它应该工作正常...... !!