引用外部css时代码如下:
1 |
<link rel = "stylesheet" type = "text/css" href = "style/main.css" /> |
将main.css放在了style目录下。
main.css中定义以下属性时背景图片无效:
1 2 3 4 5 6 7 8 |
#site_title h1 a { display: block; width: 180px; height: 40px; color: #000; text-indent: -10000px; background: url(images/logo.png) no-repeat top left; } |
用chrome浏览器的审查元素功能,可以看到:
1 2 3 4 5 6 7 8 |
background-image: url(http://zhongtian.t.com/style/images/logo.png); background-position-x: 0%; background-position-y: 0%; background-size: initial; background-repeat-x: no-repeat; background-repeat-y: no-repeat; background-attachment: initial; background-origin: initial; |
原来这里继承了style目录。
解决方法:
将main.css移到根目录,引用外部css时代码改成:
1 |
<link rel = "stylesheet" type = "text/css" href = "main.css" /> |
或者main.css中使用绝对链接,在或者使用../表示上级目录。
发表回复