- This topic is empty.
July 22, 2016 at 2:14 pm #243782tomtomParticipant
I was just thinking …
in HTML, classes and IDs are assigned with tag attributes:
In CSS they are referred with div.foo and div#bar
This is no matching syntax …
how nice would it be if we could write this in html instead:
<div.foo>… or <div#bar>… or <div.foo.fooo#bar>…
it would be shorter and more consistent declaration of classes and IDs, separating them from other, more specific tag attributes.
Also, browsers may be able to parse this faster into DOM and assign styles than looking for tag id and class attributes further down the string …
This would require browser support of course, and standardization and some fallback solutions, and it’s unlikely to happen … just wanted to drop the idea and get some feedback. Maybe someone knows if this idea is “new” or came up before.July 23, 2016 at 3:07 pm #243810Chris CoyierKeymaster
That’s a neat idea! I’ve never thought of that or seen it proposed. I don’t know enough about language design to know how it would play out in reality, but it certainly seems to tie the two languages together cleverly at first glance.July 24, 2016 at 5:30 am #243813
That would indeed be neat! It would make things more consistent and easier to look up. I look forward to this idea being picked up :)July 24, 2016 at 6:49 am #243816mmcgu1966Participant
IIRC, you can have a dot in a class or ID name, so that could prove interesting if you had an element with id=”.madness”.. would it look like this: “<div#.madness”> or if it was class=”.madness” it would be “<div..madness”>July 25, 2016 at 6:33 am #243859nkriscParticipant
A cool idea, but I think it just makes it harder to read. Though I guess if you could put spaces between it’d be OK.July 26, 2016 at 5:40 pm #243919joshParticipant
@mmcgu1966, You are correct; this is from the W3C spec: “In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit.”July 27, 2016 at 1:30 am #243927Paulie_DMember
Here’s my problem
Does this have one classs
.foo.foooor two (
fooo)?July 27, 2016 at 4:06 am #243928
I see what you mean. It could be considered as both. Problem, yes :) We could agree only one dot would be allowed? And that further classes would have to be written separately, such as
But then again, this all complicates the matter. I prefer to keep things simple. But it was a nice idea :)July 27, 2016 at 5:02 am #243929
Love this idea. To overcome the mentioned problem by Paulie_D why not use this:
in stead of:
(separation by spaces)July 27, 2016 at 5:06 am #243930July 27, 2016 at 5:06 am #243931
Ok i give up… Sorry.July 27, 2016 at 8:11 am #243952
You could post it in between three backquotes maybe? :DJuly 27, 2016 at 8:12 am #243953
Actually my code did not go well either :DJuly 29, 2016 at 1:21 pm #244053tomtomParticipant
Thanks for the thougts, its interesting to read approvals and caveats, even if implementation is unlikely anyway.
I didn’t realize that class and ID names can contain . and they have to be escaped with a backslash in css to be different from referring to
learnt something new, even if it’s rather strange to me this is even possible … well, html was there before css i guess.
So if this was done, it may have to be like
<div #lama .foo .bar>to work, leaving css syntax again,
or forbid the . in classes and IDs in html …
- The forum ‘Other’ is closed to new topics and replies.