Apply CSS to a specific View in Ruby on Rails

On a page with a web application made with Ruby on Rails, the characters in the table made with the Table tag were aligned. It looks bad as it is, so I investigated how to apply CSS so that it is vertically centered, so I will leave it as a memo for myself.

    1. What should I fix?

Files in / marketpurser / app / assets / stylesheets. If you add it to application.scss that exists by default, it will be applied to all views. Also, if you add it to the .scss file that corresponds to the name of the View, it will only apply to a specific View.

  1. How should I describe it?

It seems that the same grammar as CSS is fine. This time, I want to apply it to the td tag in the table tag that has the table class, so I wrote it as follows.

/marketpurser/app/assets/stylesheetssample.scss


table.table td {
 vertical-align:middle;
}

sample.html.erb


<table class="table">
  <thead>
    <tr>
      <th>#</th>
      <th>Info</th>
    </tr>
   </thead>
   <tbody id="myTable">
    <tr>
      <td>1</td>
      <td>data1</td>
    </td>
   </tbody>
</table>

solved. In addition, instead of simply reloading the browser, the CSS was not reflected unless I accessed the modified View page again. (Primitive mistake)

That's my personal note.

Recommended Posts

Apply CSS to a specific View in Ruby on Rails
[Rails] How to load JavaScript in a specific view
How to display a graph in Ruby on Rails (LazyHighChart)
(Ruby on Rails6) Creating a database and displaying it in a view
(Ruby on Rails6) Creating data in a table
[Ruby on Rails] How to install Bootstrap in Rails
Change from SQLite3 to PostgreSQL in a new Ruby on Rails project
How to create a query using variables in GraphQL [Using Ruby on Rails]
[Introduction] Try to create a Ruby on Rails application
[Ruby on Rails] How to write enum in Japanese
[Ruby On Rails] How to reset DB in Heroku
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Ruby on Rails Japanese-English support i18n
[Ruby On Rails] De-root_path! Redirect notation from a nested "child" view to a nested "parent": show
I want to add a browsing function with ruby on rails
Things to remember and concepts in the Ruby on Rails tutorial
Steps to build a Ruby on Rails development environment with Vagrant
(Ruby on Rails6) Create a function to edit the posted content
[Ruby on Rails] How to use CarrierWave
How to insert a video in Rails
Ruby on Rails in Visual Studio Codespaces
[Rails] Use validation on a specific controller
Deploy to Heroku [Ruby on Rails] Beginner
Steps to set a favicon in Rails
Preparing to introduce jQuery to Ruby on Rails
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
Beginners create portfolio in Ruby on Rails
[Ruby on Rails] Button to return to top
How to build a Ruby on Rails environment using Docker (for Docker beginners)
How to implement gem "summer note" in wysiwyg editor in Ruby on Rails
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
A series of flow of table creation → record creation, deletion → table deletion in Ruby on Rails
[Rails] How to apply the CSS used in the main app with Administrate
Deploy to Ruby on Rails Elastic beanstalk (EB deploy)
Convert to a tag to URL string in Rails
[Ruby on Rails] How to display error messages
How to add / remove Ruby on Rails columns
Recommendation of Service class in Ruby on Rails
Rails new in Ruby on Rails ~ Memorandum until deployment 2
Introducing Rspec, a Ruby on Rails test framework
[Ruby on Rails] A memorandum of layout templates
How to implement a like feature in Rails
How to easily create a pull-down in Rails
Rails new in Ruby on Rails ~ Memorandum until deployment 1
How to make a follow function in Rails
[Ruby on Rails] How to use session method
I made a portfolio with Ruby On Rails
How to resolve errors that occur in the "Ruby on Rails" integration test
A memo to simply create a form using only HTML and CSS in Rails 6
How to implement image posting function using Active Storage in Ruby on Rails
[Ruby on Rails] Try to create a service that makes local cats happy
Ruby on Rails Elementary
Ruby On Rails Association
Method summary to update multiple columns [Ruby on Rails]
How to implement a like feature in Ajax in Rails
[Ruby on Rails] How to change the column name
[Updated from time to time] Ruby on Rails Convenient methods
[Ruby on Rails] Change URL id to column name
I want to use a little icon in Rails