question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for `:matches()`

See original GitHub issue

Current support only shows in Safari and Firefox and Chrome maintain an older syntax. I think it’s safe to assume :matches() will eventually be adopted widely by browser vendors.

// Firefox Stable
:-moz-any(a) {
  color: blue;
}

// Chrome Stable
:-webkit-any(a) {
  color: blue;
}

// Safari Stable
:matches(a) {
  color: blue;
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
tedwcommented, Dec 9, 2020

@simevidas Thanks for the quick reply! Here’s my use case for reference:

:is(h1, h2, h3, h4, h5, h6) + :is(h1, h2, h3, h4, h5, h6) {
  margin-top: 0;
}

I was hoping to avoid generating every heading combination, especially since this code is nested in another selector in my project, so was going to do this:

:-webkit-any(h1, h2, h3, h4, h5, h6) + :-webkit-any(h1, h2, h3, h4, h5, h6) {
  margin-top: 0;
}
:-moz-any(h1, h2, h3, h4, h5, h6) + :-moz-any(h1, h2, h3, h4, h5, h6) {
  margin-top: 0;
}
:is(h1, h2, h3, h4, h5, h6) + :is(h1, h2, h3, h4, h5, h6) {
  margin-top: 0;
}

However, you‘re probably right that nesting is the best solution for now:

h1, h2, h3, h4, h5, h6 {
  & + h1,
  & + h2,
  & + h3,
  & + h4,
  & + h5,
  & + h6 {
    margin-top: 0;
  }
}

Although it makes me feel good to reduce the amount of generated CSS, I realize the extra bytes are negligible after gzipping 😄.

P.S. Thanks for all the work you do for the web dev community! Been following you on Twitter and reading your blog posts for a long time.

2reactions
yisiblcommented, Oct 17, 2017

@ai Sorry to reply you so late.

For example, ‘:any’ does not support nesting.

  • :matches(:matches(h1, h2), h3) 👍
  • :-webkit-any(:-webkit-any(h1, h2), h3) 👎
Read more comments on GitHub >

github_iconTop Results From Across the Web

matches() DOM method | Can I use... Support tables for ...
matches() DOM method. - LS. Method of testing whether or not a DOM element matches a given selector. Formerly known (and largely supported...
Read more >
MATCH function - Microsoft Support
How to use the MATCH function in Excel to search for a specified item in a range of cells, returning the relative position...
Read more >
Element.matches() - Web APIs - MDN Web Docs
The matches() method of the Element interface tests whether the element would be selected by the specified CSS selector.
Read more >
Regular Expression Matching - LeetCode
Given an input string s and a pattern p , implement regular expression matching with support for '.' and '*' where: '.' Matches...
Read more >
re — Regular expression operations — Python 3.11.1 ...
Changed in version 3.5: Added support for group references of fixed length. (?<!...) Matches if the current position in the string is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found