ValeriiVasin
ValeriiVasin

Reputation: 8716

Haml: How to set inline style for element in HAML

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?

Upvotes: 69

Views: 93904

Answers (5)

Manoj Thapliyal
Manoj Thapliyal

Reputation: 577

If you are looking inline css for image :

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

Upvotes: 1

Incerteza
Incerteza

Reputation: 34934

No need to use %div:

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

Upvotes: 19

Vitaliy Yanchuk
Vitaliy Yanchuk

Reputation: 1501

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

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

Upvotes: 3

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"].

Upvotes: -2

dnch
dnch

Reputation: 9605

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;" }

Upvotes: 133

Related Questions