Itzamacko
Itzamacko

Reputation: 39

Rails Haml element styling

I have a custom style in my css for a background image I want to apply:

.specialbg {

 background-image: url('http://i.imgur.com/XMuKF.jpg') no-repeat center center fixed;
 -webkit-background-size: cover;
 -moz-background-size: cover;
 -o-background-size: cover;
 background-size: cover;

 }

I want to apply this style to my body element in HAML, but I'm not sure how the arguments are setup. I'm thinking that the following should work:

%html
 %head
  %body
   .specialbg

But it doesn't. I've read the haml styling reference manual, but can't see where I'm wrong -- I've just adopted haml, and I'd appreciate any help or pointers!

Stack Q's I've referenced:

scaml "illegal nesting" error

Background images do not render on Ruby on Rails application

Upvotes: 1

Views: 1444

Answers (1)

Dan McClain
Dan McClain

Reputation: 11920

To add the class to your body element, you would just append the class to the tag like this:

%html
  %head
  %body.specialbg

It could be a typo in your example, but the way your example is set up, you are putting your body tag within the head tag

If you put the .specialbg class on its own line, it will create a div inside of your body tag with class='specialbg'

Upvotes: 2

Related Questions