grautur
grautur

Reputation: 30475

Changing stylesheet for a partial

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.)

Upvotes: 0

Views: 1616

Answers (2)

Ross
Ross

Reputation: 17967

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.

Upvotes: 0

mportiz08
mportiz08

Reputation: 10308

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.

Upvotes: 2

Related Questions