scss样式没有得到应用

时间:2017-09-20 01:19:21

标签: html css sass css-selectors

<body>

    <div id="nav">
        <ul>
            <li><a href="#about">About</a></li>
            <li><a href="#history">History</a></li>
            <li><a href="#projects">Projects</a></li>
        </ul>
    </div>   

    <div id="firstRow>
        <a id="about" class="smooth"></a>
        About page goes here.
    </div> 

    ...

    <script src="bundle.js" type="text/javascript"></script>
</body>

以下是我的HTML的样子,以下是我写的scss

$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;

  div{

    #firstRow {
    height: 100px;
    background-color: green;
  }

  }

}

但风格并没有得到应用。我按照scss指南,但它不起作用。

1 个答案:

答案 0 :(得分:3)

"代码ID

中缺少

<div id="firstRow">

<body>

  <div id="nav">
        <ul>
            <li><a href="#about">About</a></li>
            <li><a href="#history">History</a></li>
            <li><a href="#projects">Projects</a></li>
        </ul>
    </div>   

    <div id="firstRow">
        <a id="about" class="smooth"></a>
        About page goes here.
    </div> 

    ...

    <script src="bundle.js" type="text/javascript"></script>
</body>

更新了SCSS脚本,您在SCSS中引用#firstRow的div元素子,但HTML引用相同的元素。

$ font-stack:Helvetica,sans-serif; $ primary-color:#333;

body {
  font: 100% $font-stack;
  color: $primary-color;

  div#firstRow {
    height: 100px;
    background-color: green;
  }

}

或者更改您的HTML代码,如下所示

<div>
    <a id="about" class="smooth"></a>

    <div id="firstRow">
      About page goes here.
    </div>
</div>