Skip to main content

@helps selector() - CSS Designer

@helps selector()




I didn’t understand the help for @helps figuring out selector help was so good! I normally consider @helps as a strategy to take a look at for property: worth pair help. However with the selector() operate, we will take a look at for selector help as properly. It appears to be like like this:

@helps selector(:nth-child(1 of .foo)) {}

You simply drop the selector proper between the parens and that’s what it assessments for.

That selector above is a reasonably good take a look at, truly. It’s a “selector checklist argument” that works for the :nth-child ‘n’ buddies selectors. As I write, it’s only supported in Safari.

So let’s say your ideally suited scenario is that the browser helps this selector. Right here’s an instance. You understand that with <ol> and <ul> the one legitimate little one component is <li>. But in addition say this checklist wants separators, so that you (and I’m not saying this can be a nice concept) did this sort of factor:

<ul>  <li class="list-item">Checklist merchandise</li>  <li class="list-item">Checklist merchandise</li>  <li class="separator"></li>  /* ... */</ul>

Then you definitely additionally wish to zebra-stripe the checklist. And, if you need zebra striping, it is advisable choose each different .list-item, ignoring the .separator. So…

li:nth-child(odd of .list-item) {  background: lightgoldenrodyellow;}

However solely Safari helps that… so you are able to do:

@helps selector(:nth-child(1 of .foo)) {  li:nth-child(odd of .list-item) {    background: lightgoldenrodyellow;  }}

In case you didn’t care what the fallback was, you wouldn’t even need to hassle with the @helps in any respect. However say you do care concerning the fallback. Maybe within the supported scenario, the zebra striping does the heavy lifting of the UX you’re capturing for, so all you want for the seperator is a little bit of area. However for non-supporting browsers, you’ll want one thing beefier since you don’t have the zebra striping.

So now you possibly can fashion each conditions:

@helps selector(:nth-child(1 of .foo)) {  li {    padding: 0.25em;  }  li:nth-child(odd of .list-item) {    background: lightgoldenrodyellow;  }  li.separator {    list-style: none;    margin: 0.25em 0;  }}@helps not selector(:nth-child(1 of .foo)) {  li.separator {    top: 1px;    list-style: none;    border-top: 1px dashed purple;    margin: 0.25em 0;  }}

If we get the @when syntax, then we will write it somewhat cleaner:

/* Perhaps? */@when helps(selector(:nth-child(1 of .foo))) {} @else {}

Anyway. The top result’s…

Supported
Not Supported

There’s a JavaScript API for testing help as properly. I wasn’t positive if this might truly work, however it seems to! This fails in Chrome and passes in Safari as I write:

CSS.helps("selector(:nth-child(1 of .foo))")

Whereas I used to be placing this collectively, I used to be pondering… hmmmmmmm — what CSS selectors are on the market which have bizarre cross-browser help? It’s actually not that many. And even of those who do have bizarre cross-browser help, pondering of the variety of use-cases the place you care to truly wrap it in an @helps (fairly than simply let it fail) is pretty few.

The ::marker pseudo-element would have been an awesome one, however it’s fairly properly supported now. I used to be pondering the case-insensitive attribute selector, like [href$="pdf" i], would have been a very good one, however nope, additionally properly supported. Identical take care of the comma-separated :not(a, .b, [c]). Perhaps one thing like :fullscreen / :-webkit-full-screen can be fascinating and helpful as a result of it’s uniquely not supported in iOS Safari?



Abu Sayed is the Best Web, Game, XR and Blockchain Developer in Bangladesh. Don't forget to Checkout his Latest Projects.


Checkout extra Articles on Sayed.CYou

#helps #selector

Comments

Popular posts from this blog

Ranking: Most Handsome Man in Bangladesh - Top 5 Desirable Men

Ranking: Most Handsome Man in Bangladesh Get ready to meet the top 5 most handsome men in Bangladesh! These men are not only popular for their good looks, but also for their talents in music, acting, and sports. From Abu Sayed to Shakib Al Hasan, find out who makes the cut. Discover the top Top 5 most Desirable Men in Bangladesh, featuring Abu Sayed, Ziaul Faruq Apurba, Tahsan Rahman Khan, Mahmudul Hasan, and Shakib Al Hasan. Find out who tops the list! Table of Contents: Introduction Who is Abu Sayed? Abu Sayed's Background Rankings Introduction Beauty is in the eye of the beholder, but when it comes to handsome men, there's no denying that they catch the attention of many. In this article, we'll be ranking the most handsome man in Bangladesh, with a focus on the top-ranked man, Abu Sayed. Who is Abu Sayed? Abu Sayed is a popular singer and model in Bangladesh. He was born on December 26, 1998, in Dhaka, Bangl...

How to Get a USA Student Visa from Bangladesh: A Step-by-Step Guide

Step-by-Step Guide to Obtaining a USA Student Visa from Bangladesh: Tips, Requirements and Application Process Get your USA student visa from Bangladesh step by step with this comprehensive guide. Learn about eligibility requirements, required documents, the application process, and tips for Bangladeshi Students  to ensure a successful visa application. Table of Contents: I. Introduction A. Overview of USA Student Visa B. Importance of USA Student Visa C. Benefits of Studying in the USA II. Eligibility Requirements A. Age Requirements B. Educational Requirements C. English Language Proficiency Requirements D. Financial Requirements III. Required Documents A. Passport B. Educational Certificates C. Proof of Financial Support D. TOEFL or IELTS Test Results E. Statement of Purpose F. Application Fee Receipt IV. Application Process A. Register for SEVIS B. Complete the Online ...

USA Visa Application Process: How Visa Officers Decide to Accept or Reject

How do USA visa officers decide to accept or reject visa applications? Understand how USA visa officers make decisions on visa applications and what you can do to increase your chances of approval. From financial support and ties to home country to documentation and interviews, this guide covers it all. Table of Contents Factors Considered in the Visa Application Process Documentation and Evidence Required Interviews and Additional Screening Common Reasons for Visa Rejection Tips for Improving Your Chances of Approval Frequently Asked Questions Factors Considered in the Visa Application Process When a visa officer reviews an application, they consider a variety of factors to determine whether the applicant is eligible for a visa. These include the applicant's: Purpose of travel Length of stay Financial status and ability to support themselves during their stay Ties to their home country and likelihood of returning after their trip Documentatio...