A guide on designing a stationary page for a Rails 4 application

Looking for advice on how to style a static page as a landing page for my Rails app. The page is generated from the StaticPagesController, but when I try to add a class in the home.html.erb file and style it in the application.css file, the styles don't seem to take effect. Any ideas on how to resolve this issue?

Answer №1

To optimize your workflow in Rails 4, it is recommended to rename the file application.css to application.scss as using the .scss extension is more efficient.

However, avoid directly inserting your code into the application.scss file as this is considered a poor coding practice.

Instead, import your .scss files (without the extension) as shown below:

*= require_tree .
 = require rails_bootstrap_forms
 *= require_self
*/

@import "yourfilename";

If you are working with the .sass extension, make sure to include the following line in your config/application.rb file:

config.sass.preferred_syntax = :sass

Keep in mind that Rails prioritizes .css or .scss extensions over .sass extensions by default.

In case you accidentally delete the content of your application.scss, remember to restore it promptly.

Answer №2

The document you are looking for is located here:

\app\views\layouts\application.html.erb

To include a link to your stylesheet, go to the head section of your file.

Alternatively, you can use @include to add your custom CSS file to the application.css file found in \app\assets\stylesheets\

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I completed the footer on my website, but as I zoom in on the page, everything becomes jumbled and overlapped

Hey there, I'm currently dipping my toes into the world of HTML and CSS with hopes of creating a visually appealing website. Everything was going smoothly until I reached the footer section. At first glance, it looked perfect but upon zooming in, all ...

Tips for ensuring uniform button height across all cards

I am seeking advice on how to align all the buttons in different cards, despite varying text lengths, to be in the same position at the end of each card. Here is an example of what I am aiming for. Below is my HTML and CSS code: * { margin: 0px; pad ...

Enhance this piece of code with JavaScript features

I recently implemented a scrolling script on my website that I found at this link: http://blog.waiyanlin.net/example/jquery/flyingtext.html. However, the animation currently scrolls from left to right and I would like it to scroll from right to left inst ...

Advanced data synchronization with Angular 7's bidirectional data binding feature

One input box allows users to enter a number, and I would like to adjust the width of the background color based on that number. The box itself will have a fixed width, but I am looking to dynamically change the width of the background color according to ...

When the text overflows from the div, place it on a new line to ensure readability

I have been struggling to make my text wrap onto a new line within the box. You can view the JS Fiddle Demo here: http://jsfiddle.net/SfG8r/1/ Essentially, I want the text to wrap onto a new line like a paragraph in a book when it exceeds the box boundari ...

html content area below the text

I'm currently working on developing a mobile webpage using jQuery Mobile. Encountering some peculiar behavior with text inside a div or table cell that has a background color. It seems to have some extra whitespace below the characters, making it app ...

Unchecking a box becomes impossible in Rails and Ajax due to boolean constraints

Even though I've come across several similar questions, I'm still struggling to make mine work correctly. Here's what my code looks like... #app/views/tasks/index.html.erb <%- @tasks.each do |task| %> <div class="task-wrapper"> ...

Having trouble locating the CSS and JavaScript files within my Spring Maven project

I have a Spring framework application with a Maven project. In addition, I have CSS and JavaScript files under the WEB-INF folder. When attempting to link the JavaScript and CSS files like this: <link rel="stylesheet" href="../allDesign/js/vendor/anims ...

What is the best way to align this form in the middle of a Jumbotron with Bootstrap 4?

<!DOCTYPE html> <head> <title>Destiny 2 App</title> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shri ...

Omit the tag from the submission section

Currently, I am utilizing a <p> tag as a submit button/area by setting a specific id in jquery. <p id="xyz"></p> My requirement is to insert an input field inside this <p> tag to include a particular value that will be submitted u ...

Choosing the :after pseudo element that comes after the p element within the container's previous element

Currently, I have a specific HTML code that is not editable: <div> <input type="text" id="name" /> </div> To add a label after the input using CSS (since "after" doesn't work on input fields), I do the following: div:after { ...

What other option can be used in place of white-space:nowrap?

When using a textarea with the CSS property white-space:nowrap, it successfully removes spaces but adds a horizontal scrollbar to the text. I want to avoid the horizontal scrollbar while also preventing scrolling using arrow keys when using overflow-x:hi ...

Transforming item design in Flexbox when it wraps

Can styles be applied once an item wraps around? I have a two-column flexbox layout where the first item is fixed to the left and the second item should be centered in the remaining space. The solution mentioned here involves adding margin: auto to the se ...

What is the correct way to make an image adjust to changes in a browser's size?

I'm in a bit of a quandary: How can I ensure that an image resizes properly based on viewport size? So, here's the challenge - I have an image that is 400 pixels wide and 400 pixels tall. My aim is for it to occupy only 90% of the width of the v ...

Style your tables so that each row changes color when hovered over

I am dealing with a large table containing multiple rows, each of which has a border of 2px solid grey. My current issue is that the entire table is linked, and I want to change the border color to black when hovering over any row. However, applying :hove ...

jQuery Slider not appearing on the page

I am attempting to incorporate the Basic jQuery Slider into my website. Below is the code I have used: For HTML file: <div id="slides"> <ul class="bjqs"> <li><a href="somelink"><img src="someim ...

Tips on setting background color for ODD and EVEN rows using PHP?

I am looking to incorporate background colors for alternating rows, with odd rows being #e5e8e8 and even rows being #b9b8bb, using CSS. for ($i = 2; $i <= $arrayCount; $i++) { $_SESSION["a"] = trim($allDataInSheet[$i]["A"]); $_SESSION[ ...

Tips for resolving issues with the header and scrolling content

I am new to CSS and I understand that it is quite simple: Question: I have a sample HTML page below, and when I scroll the page, the header does not stay fixed in one place. What am I missing here? Please assist. window.onscroll = function() { myFunc ...

"Need guidance with jQuery and CSS layout alignment on the

So here's the scenario I'm dealing with: <div id="tabs"> <div id="tab_one"> Content for tab one </div> <div id="tab_two"> Content for tab two </div> <div id="tab_three"> ...

What could be causing my table to malfunction in IE8?

Is it just me, or do my CSS tables not work on IE8? <div class="main-table"> <div class="row"> <a class="secondary-table" href="#"> <div class="secondary-row"> <div class="secondary-cell"> ...