63
votes

Here is my code:

<div class='some' style='position: absolute; left: 300; top: 300;'>..</div>

It parses only style='position: absolute', and doesn't parse the other styles. How can I achieve this?

5
The answer given is correct, but it missed a far more important point: you shouldn't ever be using inline styles. Define a CSS class and do it right. - Marnen Laibow-Koser
It was temporary solution :) try something and clear all changes. That's why I was looking for this :) - ValeriiVasin
What about when you are dynamically setting a background image? That's when I use inline styles. - Joel Brewer
@JoelBrewer I think that for that, I’d dynamically generate a CSS override file (or use JavaScript) in preference to using inline styles. - Marnen Laibow-Koser

5 Answers

127
votes

It would have been handy if you'd posted the HAML you're using, but this is how it's done:

%div.some{ :style => "position: absolute; left: 300px; top: 300px;" }
14
votes

No need to use %div:

.some{ style: 'position: absolute; left: 300px; top: 300px;' }
3
votes

Another approach in addition to the hash one by Dan Cheail is such:

%div.some(style='position: absolute; left: 300; top: 300;')
1
votes

If you are looking inline css for image :

<%= image_tag( 'image_name.png', style: 'height: 25px; width: 200px; position: absolute' ) %>
-2
votes

Requested a hash special case at: https://github.com/haml/haml/issues/787 to allow us to write:

%div{ style: { display: "none", width: "50px" } }

much like is possible for class: ["class1", "class2"].