how to convert css style syntax in haml
Asked Answered
N

3

5

I got the wrong haml in http://html2haml.heroku.com/

How to convert it in proper way ?

Because the haml didn't render the identical html when I load the page

HTML

<style media="screen">
      img { display: none; }
            body { overflow: hidden; }
            #canvas { position: absolute; top: 0; left: 0; }
</style>

HAML by http://html2haml.heroku.com/

%style{media: "screen"}
  :cdata
    img { display: none; }
    body { overflow: hidden; }
    \#canvas { position: absolute; top: 0; left: 0; }
Nocuous answered 3/8, 2014 at 6:38 Comment(3)
Why are you using inline styles? Move them to assetsGrimbal
Using inline is handy to test something works without having to recompile assets; if it works, then can move it to assetsDecarburize
For the sake of motivation, email layouts require inline stylesheets.Colpin
O
13

This should work

%body
  :css
    img { display: none; }
    body { overflow: hidden; }
    #canvas { position: absolute; top: 0; left: 0; }

P.S. But this's a bad practice to render html content which should be located in separate file.

Octodecimo answered 3/8, 2014 at 13:58 Comment(1)
This won’t include the media="screen" attribute. You’ll need to use an actual tag (e.g. %style(media="screen")) in order to get the attribute.Oratory
S
3

This should work for you, in case you don't want CDATA tokens in your code.

%style{media: "screen"}
  :plain
    img { display: none; }
    body { overflow: hidden; }
    #canvas { position: absolute; top: 0; left: 0; }
Subsistence answered 20/3, 2020 at 9:2 Comment(0)
P
2

You may want to try htmltohaml

Input:

<style media="screen">
      img { display: none; }
      body { overflow: hidden; }
      #canvas { position: absolute; top: 0; left: 0; }
</style>

Output:

%style{:media => "screen"}
  img { display: none; }
  body { overflow: hidden; }
  \#canvas { position: absolute; top: 0; left: 0; }

Anyways, as Mandeep said, I also recommend that you should move your styles to stylesheets.

Pelting answered 3/8, 2014 at 6:43 Comment(1)
It's a bad practice to use inline stylesGrimbal

© 2022 - 2024 — McMap. All rights reserved.