Frustrated by the many limitations and compatibility issues of CSS, and finding myself constantly needing to write javascript code to get my webpages to layout the way I wanted, I thought I might be able streamline future projects by ditching CSS altogether for page structuring.
I wrote a javascript library which parses layouts specified in XML files, and applies them to an HTML document using absolutely positioned and sized, non-nested divs. So the idea is that each page has an HTML file containing all content, an XML file specifying how that content should be arranged on the page, and a CSS style sheet for superficial styling.
Here is an example. (press the button to inflate the layout. tested in latest version of all major browsers.) And another.
This system degrades gracefully to plain html, and even allows for separate styling in the case that javascript is disabled.
It seems to me that this approach not only eliminates many cross-browser issues, but also allows me to achieve more complex layouts with less work. For example, my understanding is that the following cannot be done with CSS alone, at least not without a mess of nested divs:
- Set an element to fill available width or height within its parent container. (This is not the same as width/height:100% if there are other elements in the parent container.)
- Align any element top/center/bottom, left/center/right within any container, even if its size is unknown.
- Pad an element of unknown size, without increasing that elements size (For example, if a div is set to 100% of the window size, it cannot be padded without overflowing the window.)
- Automatically set all elements within a parent element to be equally spaced apart.
- Set the height of a floating element. Similarly, independently set shrink-wrapping behavior horizontally and vertically.
- Set elements to float in columns rather than rows (CSS3 seems to support columns but browser compatibility is not good)
Nonetheless, I'm sure this is considered blasphemous. So, what are the potential problems with using this system to layout web pages?
EDIT: the code is on github