Ensuring your CSS is well-organized is crucial when working with Rails.
To manage your stylesheets effectively, create a main
app/assets/stylesheets/application.css
file where you can specify all the CSS files to import for your application.
For example, if you have a separate
app/assets/stylesheets/mobile.css
file, you should include the following in your
application.css
:
/*
*= require mobile
*/
Next, make sure to include the following code within the <head>
tags on your page:
<%= stylesheet_link_tag 'application', media: 'all' %>
For more guidance on how to organize assets in Rails, refer to the following link: http://guides.rubyonrails.org/asset_pipeline.html#asset-organization
Here are some suggestions:
- Avoid mixing camelCase and dashes in your CSS.
- Avoid assigning styles to IDs.
- Minimize the use of
!important
.
Stick to using classes instead of IDs for styling, and opt for dashes (-) over camelCase. Try to limit the use of !important
, and consider referring to a CSS style guide for best practices.
Additionally, consider transitioning to SCSS for improved functionality. Rename your mobile.css
to mobile.scss
and structure it like this:
$breakpoint: 900px;
@media (max-width: $breakpoint) {
.green-button {
display: none !important;
}
.chat_button{
margin-top: 20px !important;
}
#myCarousel {
height:800px !important;
}