我试图在我的rails应用程序中添加自定义CSS表格对齐。但它似乎没有用。有人可以帮我吗?我是网络开发的新手。我同时学习HTML,CSS和Rails。 这是我的app / assessts / stylesheets / custom.css
td {
vertical-align: middle;
}
我的头标记中包含了样式标记。这是我的app / views / layout / application.html.haml
!!!
%html
%head
%title
= content_for?(:title) ? yield(:title) : "GentelellaOnRails"
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= stylesheet_link_tag 'custom'
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags
%meta{:content => "width=device-width, initial-scale=1", :name => "viewport"}/
%body.nav-md
.container.body
.main_container
- flash.each do |key, value|
#flash{:align => "center", :class => "alert alert-#{key}"}= value
= render "partials/sidenav"
= render "partials/topnav"
.right_col{:role => "main"}
= yield
= render "partials/footer"
= javascript_include_tag 'footermanifest', 'data-turbolinks-track' => true
这是我的索引文件:
%h1 Listing all patients
.x_panel
.x_content
= link_to 'New Patient', new_patient_path, class: "btn btn-primary"
%table.table.table-bordered
%thead
%tr
%th Id
%th Image
%th Name
%th Email
%th Address
%th Phone
%th Gender
%th Birthdate
%th Bloodgroup
%th Options
%tbody
- @patients.each do |patient|
%tr
%td= patient.id
%td= image_tag patient.image_url.to_s, :size => "100x80"
%td= patient.name
%td= patient.email
%td= patient.address
%td= patient.phone
%td= patient.gender
%td= patient.birthdate
%td= patient.bloodgroup
%td
= link_to edit_patient_path(patient), class: "btn btn-warning" do
= fa_icon 'pencil'
= link_to patient, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: 'btn btn-danger' do
= fa_icon 'trash'
答案 0 :(得分:1)
custom.css
中需要application.css
,例如
*= require custom
*= require_tree .
并从布局中删除行= stylesheet_link_tag 'custom'
。
重新启动服务器。