Search code examples
htmlcssdrymarkupweb-standards

Generate a CSS file from HTML markup


I create a lot of html and css pages. Is there a way to markup an html file, than generate a css file from the markup.

Here's what i'm thinking:

Example Markup

<body id="home">
   <section id="main">
       <article>
           <p>Some content</p>
       </article>
   </section>

   <aside>
       <article>
           <p>Some more content</p>
       </article>
   </aside>
</body>

Example of generated CSS

#home {  }
#home #main {  }
#home #main article {  }
#home #main article p {  }

#home aside {  }
#home aside article {  }
#home aside article p {  }

Solution

  • Yes, there is: parse the HTML and walk the DOM tree to generate your skeleton CSS file.

    PS: that IS very impractical CSS.