Hello.
I’ve been working on the way I generate HTML with PHP, and to facilitate and normalize just that I’ve made a simple HTML_Element class, which represents a tag along with it’s contents, attributes and so on. In the future, I want to be able to have individual modules which I can use anywhere without them interfering with each other, and right now the only obstacle to that, really, is CSS since it can never be scoped and I always have to keep in mind every single name in the CSS namespace so certain rules don’t “bleed” to where they shouldn’t. As mostly a C++ programmer, I’m not used to dealing with scoping and naming issues, as well as separating such interconnected layout aspects as HTML and CSS are, and though I understand why CSS is the way it is, it is by far the thing that bothers me the most in web development.
My ideal use case would be something along the lines of:
[code=php]$css_rules = new CSS_Rules;
//Configure $css_rules with all the relevant css rules…
$html_element = new HTML_Element(“p”);
//Configure the element, add children, etc….
$html_element.set_style($css_rules);
This would basically mean I wouldn’t need to worry about class names at all, and would just need to use that variable containing all the relevant rules whenever I needed it; since I cannot use inline CSS, however, (I want @media rules), I’d still have to generate names in some way, and doing so randomly isn’t really viable for obvious reasons, unless I wanted to generate the CSS with the page itself, which I don’t want to do because of caching;
Really any suggestions that you might have or any insight that would help me with this would be much appreciated.