Haml: How to set inline style for element in HAML

Ruby on-Rails-3Haml

Ruby on-Rails-3 Problem Overview


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?

Ruby on-Rails-3 Solutions


Solution 1 - Ruby on-Rails-3

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

Solution 2 - Ruby on-Rails-3

No need to use %div:

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

Solution 3 - Ruby on-Rails-3

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

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

Solution 4 - Ruby on-Rails-3

If you are looking inline css for image :

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

Solution 5 - Ruby on-Rails-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"].

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionValeriiVasinView Question on Stackoverflow
Solution 1 - Ruby on-Rails-3dnchView Answer on Stackoverflow
Solution 2 - Ruby on-Rails-3IncertezaView Answer on Stackoverflow
Solution 3 - Ruby on-Rails-3Vitaliy YanchukView Answer on Stackoverflow
Solution 4 - Ruby on-Rails-3Manoj ThapliyalView Answer on Stackoverflow
Solution 5 - Ruby on-Rails-3Ciro Santilli Путлер Капут 六四事View Answer on Stackoverflow