【问题标题】:How to apply css Styling in Ruby on Rails HTML page?如何在 Ruby on Rails HTML 页面中应用 css 样式?
【发布时间】:2020-08-13 06:59:02
【问题描述】:

我是 RoR 的新手。我正在尝试在我的表单上添加 css 类。这是我的表格:

<%= form_tag :action => 'create' do %>
  <p><label for = "name">Name</label>:
    <%= text_field 'books', 'name' %></p>
  <div class="form-control">
  <p><label for = "author">Author</label>:
    <%= text_field 'books', 'author'%></p>
  </div>
  <p><label for = "price">Price</label><br/>
    <%= text_area 'books', 'price'%></p>
  <%= submit_tag "Create" %>
<% end -%>

该表单控件不接受class="form-control mb-4 col-10" placeholder="Patient name",如&lt;input type="text" th:field="*{name}" class="form-control mb-4 col-10" placeholder="Patient name"&gt;。如何应用 css 样式。

【问题讨论】:

  • “不接受”是什么意思?您是否尝试过在 app/assets/stylesheets/*somefile*.css 中定义 css 并通过 = require *somefile.css 引用 app/assets/stylesheets/application.css 中的文件您是否尝试设置类?
  • 这能回答你的问题吗? Setting the class of HTML elements using Rails?
  • 我正在使用在线样式表 stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/…" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">斯林。
  • 另外,请看这篇文章:stackoverflow.com/questions/17507101/… 它是在 HAML 中,但想法基本相同

标签: html css ruby-on-rails ruby


【解决方案1】:

你必须把类放在逗号后面

<%= text_field 'books' :name, class:"form-control mb-4 col-10", placeholder="Patient name" %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    相关资源
    最近更新 更多