Rails:动态更改CSS属性? [英] Rails: change CSS property dynamically?

查看:77
本文介绍了Rails:动态更改CSS属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动态更改 max-width CSS属性,具体取决于与给定模型关联的图像数量。

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

如何在Rails 3.1中执行此操作?

How can I do this w/in Rails 3.1?

(Javascript& SASS / SCSS也可供我们使用)

推荐答案

我想你可以这样做吗?

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

其中 X 是单个图像的宽度。

Where X is a single image's width.

或者,您可以

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

然后为 div.images.count1 div.images.count2 div.images.count3 等......但这不是很具伸缩性,所以最好坚持使用样式属性

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

这篇关于Rails:动态更改CSS属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆