1

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

4

1 回答 1

2

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'

于 2012-08-12T12:27:03.070 回答