【问题标题】:How can I use haml to set an inline style for my ruby on rails app?如何使用 haml 为我的 ruby​​ on rails 应用程序设置内联样式?
【发布时间】:2014-05-05 19:54:28
【问题描述】:

我正在尝试使用带有 formtastic 和 haml 的 ruby​​ on rails 构建一个表单。一切正常,除了我无法在我的输入字段上设置内联样式。当文本框设置为只读时,我想将其变灰。我成功地将字段设置为只读,但样式标签不起作用。在演示站点上查看时,它实际上并没有显示在代码中。

如何使用 haml 设置内联样式?

= semantic_form_for @article do |f|
  = f.inputs do
    = f.input :id, "style" => "background-color:#000000", input_html: { readonly: true }  

根本不工作的代码是:

"style" => "background-color:#000000",

我一直在看这里:http://haml.info/docs/yardoc/file.REFERENCE.html#htmlstyle_attributes_

但我一直无法弄清楚。我还是个新手!你能帮忙吗?

【问题讨论】:

  • 请注意,我确实尝试使用以下措辞 ---> "style" => "background-color:#000000" ||没有不同的结果

标签: ruby-on-rails haml


【解决方案1】:

由于 style 是一个 html 选项,请将其添加到 input_html 哈希中。另外,请确保样式的属性、值对以分号结尾:

= f.input :id, input_html: { style: 'background-color: #000000;', readonly: true }

【讨论】:

    猜你喜欢
    • 2011-12-26
    • 2015-04-09
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    • 2012-08-26
    • 1970-01-01
    相关资源
    最近更新 更多