69

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?

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
ValeriiVasin
  • 8,628
  • 11
  • 58
  • 78

5 Answers5

133

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;" }
Community
  • 1
  • 1
dnch
  • 9,565
  • 2
  • 38
  • 41
  • 11
    It's worth noting that there cannot be a space between the end of the element or class name and the opening brace. – FreeAsInBeer Aug 27 '13 at 13:37
19

No need to use %div:

.some{ style: 'position: absolute; left: 300px; top: 300px;' }
Incerteza
  • 32,326
  • 47
  • 154
  • 261
3

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

%div.some(style='position: absolute; left: 300; top: 300;')
Vitaliy Yanchuk
  • 1,463
  • 1
  • 11
  • 22
1

If you are looking inline css for image :

<%= image_tag( 'image_name.png', style: 'height: 25px; width: 200px; position: absolute' ) %>
Manoj Thapliyal
  • 567
  • 7
  • 9
-2

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

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • 2
    Downvoting because this is not an answer to the question. It's just a statement that you made a feature request for this syntax. – Adam Mar 03 '18 at 00:08
  • @Adam thanks for feedback. My intention was to say: "this issue confirms that the perfect most intuitive syntax is not possible, let's upvote it". – Ciro Santilli OurBigBook.com Mar 03 '18 at 03:16
  • 2
    Sure, I get that. I think that would have made for a fine comment, instead of an answer. As it stands, if a user who was scanning answers didn't click the link and see the outcome of your request, they might get the impression that it was actually implemented, and you were showing an example of the new syntax as a solution, but it wasn't accepted. – Adam Mar 04 '18 at 03:49