views:

33

answers:

3

I have a Movie class in my Rails app, and I have a "_movie.html.erb" partial that displays the movie's title, its overall rating, and a brief summary.

I want a stylesheet to apply to this particular partial, but nothing else in my app.

How do I do this?

In case it helps, I don't want to do some type of CSS classing on the partial instead, because the stylesheet is a huge, gargantuan mess that's not created by me and that may be updated in the future. (For example, let's say that the partial is trying to mimic the way RottenTomatoes displays a movie.)

+2  A: 

Correct me if I'm wrong, but I don't think partials are associated with specific stylesheets.

You're probably going to have to wrap the partial in something like:

<div id="movie">
  <!-- partial code -->
</div>

Then you can just use a separate stylesheet like movie.css, which you can link in addition to the main stylesheet to do your styling (which can also go in the main stylesheet). There isn't really a way around using any id's or classes that I'm aware of.

mportiz08
How do I make sure the movie.css stylesheet applies only to the div with id="movie"? Do I have to add "#movie " to every selector in movie.css?
grautur
Yes, so styling a p tag inside of your movie section would be #movie p {css:rule;}. Styling a li item inside of a ul inside movie would look like #movie li {css:rule;}. Hope this clears it up.
Moses
A: 

I am not sure!!! But I hope this might help you.

http://www.webmasterworld.com/forum83/3922.htm

You can also improve your CSS skills at SelectOracle

Rohit
A: 

Just put all of the CSS in to one sheeet - it's better for performance reasons.

Specificity determines what CSS applies to what elements, so just style everything like so

#movie p { } 
#movie table { }
#movie h1 { }

and that css will only apply to content within #movie div. you can include 2 stylesheets if necessary to keep content separate, but it's not worth it unless you're talking thousands of lines of css, which is unlikely given its just for 1 div.

Ross