简体   繁体   中英

CSS in Rails background-color not working in body

In my application.css my I have this style:

body {
    /*background-image: url(back.jpg);*/
    background-color: #343434;
}

If I uncomment the background-image property, it works just fine but I don't want the image anymore and I want the solid color. However, the background color is not showing up.

I am using Rails 4 with Bootstrap 3 and Sass (though this file is not scss)

Any advice would be helpful.

CSS

Don't know about bootstrap specifically, but this may help resolve the problem:

html, body { background: #343434; }

This will give the whole document ( html ) a background of #343434 , which will override any of the potential presets from bootstrap


Precompile

As mentioned by Mike Riley, you may also have an assets precompile issue:

rake assets:precompile RAILS_ENV=production

This wouldn't be a problem in development (just production)

Are you using asset pipeline with Rails by chance? If so run:

rake assets:precompile

That will clear out any changes and it should show up. If you are not using asset pipeline or that doesn't work. Try inspecting the css style in the browser. Just to see if you can find anything on the page. Let me know if any of this helps.

Mike Riley

It seems you need to separate the URL with a comma.

background-image: url('back.jpg');

You can see the w3school about the syntax of background-image.
Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM