css - 设置 text_field 宽度,样式有效但类无效

标签 css ruby-on-rails

我正在尝试改变某些输入字段的大小。我可以让它与内联样式一起工作,但尝试使用 twitter bootstrap 或仅使用一个类是行不通的。

我的表格有

<tr>
    <div class="field">
      <td><%= f.label :item %></td>
      <td><%= f.text_field :item,  style: "width: 150px" %></td>
    </div>
  </tr>


  <tr class="field_100">
    <div class="field">
      <td ><%= f.label :number_of_rolls_fill %></td>
      <td><%= f.number_field :number_of_rolls_fill, class: "field_100" %></td>
    </div>
  </tr>

我看到的是

enter image description here

换句话说,内联样式有效但类无效。

我在 application.css 中设置了一个类

field_100 {
    width: 100px !important;
    background-color: #2AADD5 !important ;
}

如果我在页面上查看源代码,我会看到

<tr>
    <div class="field">
      <td><label for="bedsheet_line_item">Item</label></td>
      <td><input style="width: 150px" type="text" value="1" name="bedsheet_line[item]" id="bedsheet_line_item" /></td>
    </div>
  </tr>

  <tr class="field_100">
    <div class="field">
      <td ><label for="bedsheet_line_number_of_rolls_fill">Number of rolls fill</label></td>
      <td><input class="field_100" type="number" value="1" name="bedsheet_line[number_of_rolls_fill]" id="bedsheet_line_number_of_rolls_fill" /></td>
    </div>
  </tr>

如果我检查我尝试使用该类的第二个字段,它指向我的 style.css 主模板的第 1122 行左右。也就是下面的第二 block

  input[type="text"], input[type="password"], input[type="email"], input[type="url"], input[type="color"], input[type="date"], input[type="datetime"], input[type="datetime-local"], input[type="month"], input[type="number"], input[type="range"], input[type="tel"], input[type="time"], input[type="week"], textarea
        {
           background: #FFFFFF;
           -webkit-border-radius:4px;
           -moz-border-radius:4px;
           border-radius:4px;
           border:1px solid #B9B59D;
           margin:0 auto;
        }
        input[type="text"], input[type="password"], input[type="email"], input[type="url"], input[type="color"], input[type="date"], input[type="datetime"], input[type="datetime-local"], input[type="month"], input[type="number"], input[type="range"], input[type="tel"], input[type="time"], input[type="week"], textarea
        {
           width: 100%;
           padding: 4px 0;
           color: #302E22 !important;
           font-size: 13px;
           font-family: Arial, 'Arial Unicode MS', Helvetica, Sans-Serif;
           font-weight: normal;
           font-style: normal;
           text-shadow: none;

这些是内部使用率较低的应用程序,因此如有必要,我可以使用内联样式。但是,我想让它与类一起工作。我的计划是有不同的类,例如 field_150、field_200 等。

最佳答案

您忘记了代码中类名前面的点:

field_100 {
    width: 100px !important;
    background-color: #2AADD5 !important ;
}

您的样式只会应用于 - 标签。

使用点按类名选择:

.field_100 {
    width: 100px !important;
    background-color: #2AADD5 !important ;
}

关于css - 设置 text_field 宽度,样式有效但类无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41108410/

相关文章:

javascript - 无法让这个 JavaScript 在我的下拉菜单上工作

javascript - 打开按钮时停止图像移动

ruby-on-rails - Rails 路由 - 范围正则表达式或重定向

javascript - 在 Rails View 中从 Rails Controller 读取变量值

jquery - 为最有效的布局订购砌体元素

html - 带标题的收缩包装图像容器

ruby-on-rails - 如何在 capybara 和 poltergeist 中测试 CSV 下载?

javascript - 使用 javascript 调用 Rails Controller 方法

html - 如何使用特定形状的另一个 div 在 div 上方显示页面背景

ruby-on-rails - Rails中ActiveModel实例上的热切加载关联