On Friday, June 5, 2015, kenatsun <[email protected]> wrote:

> I (a Rails newbie) am trying to understand how CSS works in Rails, relying
> on guidance from http://guides.rubyonrails.org/configuring.html.  I'm
> getting some surprising, perplexing, and unwelcome results, regarding how
> the CSS settings cascade to different views.
>
>
>
> Clearly, there is a bug here.  Whether the bug is in in the machinery of
> Rails or in my understanding of it, I can't tell.  What I would like to
> know is, how (or where) to set CSS attributes so they apply to the displays
> of just one model.
>
>
>
The default setup is that all of your CSS is loaded all the time. While it
might seem wasteful to load CSS that isn't needed on a given page, the
rationale is that this allows the browser to load a single CSS file on
first visit that is then cached for subsequent pages.

In development the CSS files are fetched individually but the result is the
same. There is nothing that says that the styles from users.scss should
only apply to pages rendered by the users controller, nor is there an
inheritance chain. If you want these things, you must set them up yourself,
for example by setting a class on some appropriate element of the DOM based
on the current controller and then changing the selectors in your CSS files

In the presence of conflicting CSS directives the browser picks the most
specific one (eg #foo .title is more selective than just .title) - see
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity for example.

Fred

>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CABp077X9QM6Hh7ydRfSYHnTNT27p_REF41KJNEULeh3oZpZrXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to