craftdeer
craftdeer

Reputation: 1025

How to put different background images for each page in rails?

I have 3 pages in my rails website and I would like to put different background image in each of them. If I do

body {
   background-image: url("myimage.jpeg")
}

It will put the same background image on all of the pages. So I wrapped all the html code of each page in a main .class container and set the background image of the container which did the trick. But doing this leaves a little white space on the bottom part of the page and the background does not fully occupy the bottom part even when I do this

.wallpaperdiv {
      background-image: url("wallpaperbackground.jpeg");
      background-attachment: fixed;
      background-position: cover;
      background-repeat: no-repeat;
      background-size: 100%;
            }

The first code that targets "body" instead of the class doesn't leave any white space. What would I have to do to remove the white space at the bottom?

Upvotes: 1

Views: 662

Answers (1)

Sebastián Palma
Sebastián Palma

Reputation: 33420

You can add a class attribute the body tag depending on the action it responds, for instance if you have a foo, bar and meh method in a controller Main, then you can do:

<body class="<%= params[:action] %>">

It'll produce a tag like <body class="foo"> depending on the current action. So then you can create your CSS styles like:

body.foo { ... }
body.bar { ... }
body.meh { ... }

Note if you have more than one method with the same name, you'd probably need to add some extra info to the identifier.

Upvotes: 3

Related Questions