html - 背景图片不显示?

标签 html css sass 960.gs

好的,我有下面的html代码

<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="css/reset.css" type="text/css"/>
        <link rel="stylesheet" href="css/style.css" type="text/css"/>
        <title>marriage</title>
</head>
<body>
<div id="container">
    <div id="logo">
        <h1><a href="#">marriage logo</a></h1>
    </div> <!-- end logo -->
    <div id="input">    
        <input type="text" name="search" id="search" />
        <input type="submit" value="search .." />
        <p>search for words like: calm, honest ... etc</p>
    </div> <!-- end input -->
    <div id="questions">    
        <h2>Why our website ?</h2>
        <p>because you find your soulmate as easy as possible, just type the word you looking 
            for in your soulmate and press enter to start searching</p>
    </div> <!-- end questions -->
    <div id="side">
        <p>New User or signup if not</p>
    </div>  <!-- end sidebar -->
    <div id="footer">
        Copyrighted &copy; 2012
    </div> <!-- end footer -->
</div> <!-- end of container -->
    </body> 
    </html>

这是样式的 scss 文件,我使用 960 网格系统进行布局

@import "compass";
@import "960/grid";

$ninesixty-columns: 12;

html, body {

  @include background-image(linear-gradient(#fcfad0, #FFF));
  width: 100%;
  height: 100%;
 }

#container {

@include grid_container;

#logo {
    @include grid(6);
    // @include clearfix;
    h1 {
        background: url(images/logo.jpg) no-repeat;
        width: 480px;
        height: 250px;
        text-indent: -9999px;

        a {

            text-decoration: none;
        }
    }   
}
  } 

<h1> 中的背景图片标签没有与 html 文件一起显示,我不知道为什么.. 这里缺少什么吗?

h1 {
        background: url(images/logo.jpg) no-repeat;
        width: 480px;
        height: 250px;

   }

最佳答案

我看到你在使用 Compass。因此,您已经在配置文件中配置了包含图像的目录(即 images_dir)。
不要直接调用你的图像,你应该使用 image-url() helper,像这样(不指定目录图像):

background: image-url(logo.jpg) no-repeat;

另外,如果你想隐藏文本,你可以使用mixin @hide-text .最后,也许是 @replace-text-with-dimensions mixin 就是你想要的:

h1 {
  @include replace-text-with-dimensions(logo.jpg, 0, 0);
}

但是,我想您想让 Logo 可点击。在这种情况下,代码将是:

<h1 id="logo"><a href="/">marriage logo</a></h1>

和:

#logo {
  a {
    @include replace-text-with-dimensions(logo.jpg, 0, 0);
    display: block;
  }
}

关于html - 背景图片不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10053178/

相关文章:

html - 使用 HTML 属性进行 knockout validation

javascript - 我可以自动将数据附加到链接吗?

css - 播放器 vimeo 覆盖播放按钮 css

html - 与同一行中另一列高度相同的响应图像

css - 在 JSF Web 应用程序中使用 SASS

html - 如何在文本旁边正确添加按钮或图标?

javascript - 我可以在单个警报中对 javascript 数组的所有元素进行alert() 吗?

html - IE中让iframe填充div的剩余高度

css - Chrome CSS3 边框底部过渡错误

css - 滚动不显示整个元素列表