我如何设计内联样式?

时间:2013-08-17 00:23:28

标签: css ruby-on-rails

我如何将#{self.o_cord.name}和#{self.o_product.full_name}设为内联样式,使其背景颜色为橙色?它们在.rb文件中,我不确定是否会改变任何内容。提前谢谢!

if self.o_connection.dongle? 
  return "Plug the #{self.o_cord.name} end of the #{self.o_product.full_name} into the #{self.i_product.full_name}."

2 个答案:

答案 0 :(得分:0)

我会将字符串保留在您的模型之外,而是调用o_connection.dongle?从你的角度来看。然后在您的视图中,您可以通过css简单地将关键字包含在范围和样式中。

查看:

<% if SomeClass.o_connection.dongle? %>
  <p>Plug the <span class="info-label"><%= self.o_cord.name %></span> end of the <span class="info-label"><%= self.o_product.full_name %></span class="info-label"> into the <span><%= self.i_product.full_name %></span>.</p> 

CSS:

span.info-label {
  background-color: 'orange';
}

答案 1 :(得分:0)

Haml Inline css示例:

= f.text_area :short_description, :style =>'background-color:'orange';'

ERB

<%= f.text_field :short_description, :style => 'background-color:'orange';' %>
相关问题