3

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 {  }
8
  • 2
    I would take a look at CSS Lint -- that type of generated CSS would be highly impractical. Never use 2 IDs, and CSS lint actually recommends never using them at all. Commented Aug 16, 2011 at 21:09
  • 3
    CSS lint is stupid when it comes to recommending not using ids. Commented Aug 16, 2011 at 21:10
  • 1
    Unless you have another process that strips out any empty css rule, this would leave too much unused css, bloating your css files and making your site slow. Commented Aug 16, 2011 at 21:12
  • 2
    It would be quite easy to do that, but you'll get a giant CSS that is of no practical use to you. Better analyse the code yourself and add only the styles you need. The result will be better and you'll get there faster. Commented Aug 16, 2011 at 21:12
  • 1
    I believe this same question was answered at stackoverflow.com/questions/4574208/…. Commented Aug 16, 2011 at 21:21

1 Answer 1

2

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

PS: that IS very impractical CSS.

Sign up to request clarification or add additional context in comments.

3 Comments

I agree that it's impractical css, but it makes the file very readable and it ends up saving time with future edits.
@Dan: Less time typing new selectors, more time hunting for the selectors. Unless your pages are small I'd think the usual way would be faster.
Hmm... is this the answer of the first-name users?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.