-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS pseudo-selector for h1-h6? #1008
Comments
Peanut gallery here. :heading seems ultra specific. Maybe we would be better served by a tag selector? Something like /h[0-6]/ {
font-weight: bold;
} With custom tags in html, there is a good use case for prefixed elements
would be selected by /react-*/ {
font-weight: bold;
} |
There is the CSS Custom Selectors proposal (it even has its PostCSS plugin) which would solve this exact issue and much more. But doesn't |
See #1010 |
whatwg/html#3499 contains a |
No, because HTML has ways of assigning heading levels that go beyond tagnames - |
Would |
Nah, none of those are "headings" in HTML's semantics. They're labels for some content, which serve a similar purpose, but aren't the same thing. |
|
@inoas are there any other HTML tag names, other than H1–6 where a regex-like selector like that would make sense? If you're wanting to select tags by partial tag name like that, though CSS selectors won't currently do it, you can do this with XPath using a selector like: |
It's not a valid selector, but it's also a remarkably complex feature for something as limited as "match this family of tagnames". LIke @tomhodgins says, there's very little call for substring-matching on tagname; insofar as we do want such a thing, prefix/suffix-matching like XPath provides probably provides 90%+ of the desired functionality. But such a thing wouldn't even work here, because part of the point of a heading-level selector is that it works off of the HTML outline algorithm, not the tagname. |
Hm. Then I guess a related Iʼm not sure what to do with |
@emilio raised an interesting concern that I don't have a good solution for. If you have :heading(1) { ... }
:heading(2) { ... }
:heading(3) { ... } and then for some reason you end up with a level 4 heading on your page, the ideal "failure mode" is that it'll render the same as 3. Maybe instead what you want is Thoughts? Unless there's a relative clear answer here I'm inclined to leave this feature out of whatwg/html#3499 and save that for a future iteration. cc @hober |
@js-choi's idea in whatwg/html#3500 might be another way out here, but that looks quite involved as well. |
An alternative idea is saying that |
I wouldn't want that to be the default behavior, but if this selector is adopted, I think it does make sense to add a second syntax that supports inequalities. It could be harmonized with the syntax being discussed in #4140 for
(Edit: and now I see that this is the exact proposal from the HTML issue linked by Anne) |
Don't work with Selenium :-( |
%heading works… |
I frequently find myself writing CSS like this:
It annoys me that I have to type
h1, h2, h3, h4, h5, h6
so much. But it gets worse:or even
Wouldn't it be nice to just type
or
or
:heading
just matches h1-h6. It would be easy to implement for browser vendors and easy to polyfill. But extremely helpful.Having a heading selector like
:heading
would be AWESOME!The text was updated successfully, but these errors were encountered: