【问题标题】:Invalid CSS after "...trap-sprockets"": expected selector or at-rule, was "@import "bootst...""...trap-sprockets"" 后的 CSS 无效:预期的选择器或 at-rule 为 "@import "bootst..."
【发布时间】:2016-03-02 08:30:20
【问题描述】:

我对 Rails 非常陌生,编程正在尝试自学。我用引导程序制作了一个简单的 Rails 应用程序。我面临的问题是我添加了带有固定顶部的引导导航栏,然后我添加了

body {
padding-top: 60px;

}

但我陷入了错误:

Sass::SyntaxError in Pages#dashboard

Showing C:/Sites/tapo/app/views/layouts/application.html.erb where line #5 raised:

Invalid CSS after "...trap-sprockets"": expected selector or at-rule, was "@import "bootst..."

Rails.root: C:/Sites/tapo
Application Trace | Framework Trace | Full Trace

app/assets/stylesheets/application.css.scss:20
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___552321104_73620060'

我的 application.html.erb

    <!DOCTYPE html>
<html>
<head>
  <title>Tapo</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>
    <nav class="navbar navbar-default navbar-fixed-top">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Brand</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
</nav>
<div class="container">
<%= yield %> 
</div>
</body>
</html>

我的 aplication.css.scss

    /*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 *= require_tree .
 *= require_self
 *= require font-awesome
 */

@import "bootstrap-sprockets"
@import "bootstrap"

body {
    padding-top: 60px;
}

【问题讨论】:

    标签: ruby-on-rails sass


    【解决方案1】:

    尝试关闭您的 @import 行,如下所示:

    /*
     * This is a manifest file that'll be compiled into application.css, which will include all the files
     * listed below.
     *
     * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
     * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
     *
     * You're free to add application-wide styles to this file and they'll appear at the bottom of the
     * compiled file so the styles you add here take precedence over styles defined in any styles
     * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
     * file per style scope.
     *
     *= require_tree .
     *= require_self
     *= require font-awesome
     */
    
    @import "bootstrap-sprockets";
    @import "bootstrap";
    
    body {
        padding-top: 60px;
    }
    

    【讨论】:

    • 应该注意的是,通常人们会遇到这个问题,因为他们正在遵循使用 SASS 设置引导程序的教程。 SASS 不需要像 SCSS 那样在每行末尾使用分号,这是 OP 使用的。
    猜你喜欢
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多