~ Ken

>
> 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. 
>
> There *does *seem to be a de facto inheritance chain (or precedence 
> ordering) among my three *.scss* files (in descending order of 
> precedence, the chain is *users.scss, toys,scss, scaffold.scss*) - that 
> is, if I add a style to any of these, it trumps those later in the chain; 
> if I remove a style, it exposes the one following it in the chain.  
>  
>
What I don't understand is how this particular chain got established, and 
> why.  In other words, why are there separate *scaffold.scss, users.scss, 
> **toys.scss, 
> *and other *<model-name>.scss *files in the standard generated Rails 
> setup?  Why not just one *.scss* file for all application-wide styles?  
>
>
Inheritance is the wrong way to think about it: there is a single flat 
namespace, conflicts are resolved by specificity as described in the 
document linked earlier. The behaviour you observe simply means that (for 
example) the styles you've added/removed to users.css had higher 
specificity to the ones in the other stylesheets. If there is a tie on 
specificity of a selector then the last selector ones. Which files 
selectors are in doesn't matter, other than it having some influence on 
which occurrence of a selector is last.


And if I want a particular style sheet to be scoped to something less than 
> the whole app, where do I put it or references to it?
>
> I just noticed this in the application.css file.  It seems to speak to 
> these questions, but I don't understand it:
>
>  * 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.
>
>
It's trying to discourage you from adding straight to application.css - it 
creates clutter. You can setup an entirely separate manifest (I've commonly 
see applications have a separate admin.css) and then change 
stylesheet_link_tag to load that css file instead of application.css for 
some pages. Most of the time you just want to make the selectors specific 
enough that they only apply to content on the relevant pages.

For example if the body elements on all the pages rendered by the users 
controlled have class "users" then a selector of the form

body.users h1 {
...
}

would only affect h1 tags on pages from that controller (the application 
layout is a good place to enforce this sort of thing)
 
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/342a0b3e-90d2-4831-a80e-09aaf1d18739%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to