You can also hit the ugly points very quickly.
E.g., suppose I want to draw diagrams of text connected by Bezier curves. Looks like SVG is the obvious choice for me. But suppose I add editable text to the mix-- well, HTML5 certainly has plenty of options for me there. And the Javascript to glue a solution together however I want.
Yet, none of those options come with any CSS that allows me to align the baseline of the text in my choice of HTML element with an SVG text element of my diagram. I have to scour Stackoverflow for some holy-shit hack of nested div bullshit just to tell the browser to position HTML stuff the way it does for an SVG text element.
These rought seams joining SVG, HTML, and CSS remain very frustrating until you start reading the specs and list archives to figure out that they were very different tech developed by very different teams with very different initial purposes and use cases in mind
(That's not to say there aren't Javascript exeskeletons that inject the SVG directly into your DOM for you.)
Covering a image with something (whether SVG or not) is very common, though most of the time the image’s size will be known, or at least known in one axis. We’re talking things like putting captions on top of images.
Needing hover effects to render on top of elements around is even more common—if you want a row of buttons that share borders, by far the easiest way involves this very situation. Example where `position:relative` does the magic:
data:text/html,<style>button{border:2px solid red}button:is(:hover,:focus,:active){border-color:lime;position:relative}button+button{margin-left:-2px}</style><button>ⅰ</button><button>ⅱ</button><button>ⅲ</button>It doesn't make them any less of a hack.
I know many things that are hacks and that I will acknowledge are hacks, but these two aren’t hacks at all. They’re straightforward and natural CSS, working in exactly the way it was designed (and in areas where that design is completely sensible).
The absolute "obvious ways":
- a wrapper div that has to be position: relative. And a display block/inline-block because otherwise it won't work. An svg and an image inside that div. The svg has to be position: absolute.
- a full-blown grid. Two elements must be forced to occupy the same cell in the grid
Ah yes. Absolutely logical and coherent and not hacks at all.
> Getting hover effects to render on top, well, I wouldn’t consider that a hack either, though it’s a little more subjective
"Not a hack": rendering is done in order, but you still have to "shunt the hovered element onto a new layer or increasing its z-index above".
And this still doesn't precisely solve the problem of "outlining a hovered element so that outline/shadow covers other items around". Because most likely you'll have layers on top of layers of "logical coherent" wrapper divs to make everything work together, and you have to spend some time figuring out how to make that particular problem actually work.
And god forbid you want to make it pretty: https://tobiasahlin.com/blog/how-to-animate-box-shadow/
Not everything is straightforward, but the things I was talking of are. (Incidentally on the matter of performance on animating box shadows, that’s actually not fundamental; Firefox has proper GPU rendering of it all, via the WebRender project, so that advice is irrelevant and actually (negligibly) slightly harmful in Firefox; it’s just that Chromium and WebKit haven’t caught up.)
We can certainly get a lot of work done within CSS's limits
All I really want is a linear model over current layout model. E.g.
...your regular css...
.wrapper:relations {
div.text/left == svg.line.underliner-segment/left + 5px
div.text/baseline == svg.line.underliner-segment/bottom + 2px
#item-a/center-x == #item-b/center-x
#item-d/right >= #item-c/left + 20px
*/right <= $this/right - 10px
*/bottom <= $this/bottom - 10px
}
I don't want play a detective with css properties ever, when there is a proper mathematical model for coordinate relations. Those who are fine with current CSS could then continue to craft wands and potions and everyone'd be happy.Thanks for this but
> I don't want play a detective with css properties ever, when there is a proper mathematical model for coordinate relations.
Designers and UI devs would probably rather just write custom shaders on canvas if they have that level mathematical prowess. For most, offloading that cognitive load to an abstraction like CSS is worth it. Let the browser do the math. Playing detective then seems like a woefully arbitrary issue to have.
Those who are fine with current CSS could then continue to craft wands and potions and everyone'd be happy.
I believe it's called the dark arts.
Sounds challenging to implement that in straight CSS :) I'd love to see a demo
I'd appreciate a visual example of what you are talking about. Seems like a far fetched, obscure-as-hell example to use as an argument. A strawman as they would say. CSS isn't perfect but it's pretty damn powerful for something I can teach a 9 year old.
We can certainly get a lot of work done within CSS's limits. For the auto-generated billion div soup, god speed and good luck.