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

Discover and Watch Reddit Videos in One Place with Reddit Tube

Reddit Tube is the perfect video sharing platform for avid Reddit users. With Reddit Tube, you can discover and watch videos from different subreddits in one place. This saves you time and enhances your user experience. Give it a try and discover new and exciting videos today! Table of Contents: I. Introduction II. What is Reddit Tube? III. How to Use Reddit Tube? IV. Advantages of Reddit Tube V. Conclusion I. Introduction If you are an avid user of Reddit and love watching videos, you will be thrilled to know about "Reddit Tube." Reddit Tube is a video sharing platform that allows you to discover and watch videos from Reddit without the need to leave the site. II. What is Reddit Tube? Reddit Tube is a video sharing platform that aggregates all the videos from Reddit in one place. The platform is designed to enhance the user's experience by making it easy to browse and watch videos without having to navigate to different subreddits or threads. Reddi...

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...

Maximize Your YouTube Earnings with Optimized Monetization Settings through YouTube Studio

Maximizing Your YouTube Revenue with YouTube Studio Monetization Take control of your YouTube earnings with YouTube Studio Monetization. Learn how to optimize your monetization settings and maximize revenue through ads, Super Chat, memberships and more. Get started now. Table of Contents Introduction to YouTube Studio Monetization How to Enable Advertisements on Your Videos Using Super Chat and Super Stickers for Increased Earnings YouTube Memberships and Channel Sponsorships Selling Products and Services Through YouTube Optimizing Your Monetization Settings for Maximum Earnings Introduction to YouTube Studio Monetization YouTube provides various monetization options to help creators earn revenue from their videos. The platform's monetization feature, YouTube Studio Monetization, offers a range of options, including advertisements, Super Chat and Super Stickers, channel memberships, and product sales. In this article, we will explore each of these monetizat...