Draft on Rails. Bootstrap is connected. I do separately Header for the site. But how to use the css file only for Header?

In the folder /app/views/layout created _header.html.erb where the menu structure itself.

In the folder /app/assets/stylesheets file header.scss

In /config/initializers/assets.rb added Rails.application.config.assets.precompile += %w( header.css )

In application.html.erb added <%= stylesheet_link_tag 'header' %> .

Rendered in application.html.erb :

 <body> <%= render 'layouts/header' %> <div class="container"> <%= yield %> </div> <%= render 'layouts/footer' %> 

The CSS file works, but works for the entire site, not for Header. How to make layouts/header render with header.scss file?

  • Do you want to apply a certain CSS file only to a piece of the page? So what? - D-side
  • Yes, that's exactly what I want. Apply a separate CSS file is valid only for footer or header - Serega Bondarenko
  • Then no way. CSS, if present, acts on the whole page. Scoping from the specification thrown out. Use CSS selectors. - D-side
  • And he did. Thanks for the answer! - Serge Bondarenko

0