1

I have a need to change the max-width CSS property dynamically depending on how many images there are associated with a given model.

How can I do this w/in Rails 3.1?

(Javascript & SASS/SCSS also at our disposal)

1
  • Could that property be in the style of the given tag? Commented Aug 11, 2011 at 0:51

1 Answer 1

5

I suppose you can do this?

<div style="max-width:<%= @somemodel.images.size * X %>px"> ... </div>

Where X is a single image's width.

Alternatively, you can do

<div class="images count<%= @somemodel.images.size %>px"> ... </div>

And then have CSS rules for div.images.count1, div.images.count2, div.images.count3 etc.. but that's not very scalable, so better stick with a style attribute

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.