Ads
Sunday, March 31, 2024
Mostly Cloudy today!
With a high of F and a low of 35F. Currently, it's 52F and Fair outside.
Current wind speeds: 9 from the Southeast
Pollen: 0
Sunrise: March 31, 2024 at 06:36PM
Sunset: April 1, 2024 at 07:15AM
UV index: 0
Humidity: 36%
via https://ift.tt/CuN3GTM
April 1, 2024 at 10:04AM
Saturday, March 30, 2024
Clear/Wind today!
With a high of F and a low of 36F. Currently, it's 46F and Clear outside.
Current wind speeds: 16 from the Southeast
Pollen: 0
Sunrise: March 30, 2024 at 06:38PM
Sunset: March 31, 2024 at 07:14AM
UV index: 0
Humidity: 65%
via https://ift.tt/IyDupOg
March 31, 2024 at 10:04AM
Friday, March 29, 2024
Partly Cloudy today!
With a high of F and a low of 28F. Currently, it's 45F and Partly Cloudy outside.
Current wind speeds: 13 from the Northeast
Pollen: 0
Sunrise: March 29, 2024 at 06:39PM
Sunset: March 30, 2024 at 07:13AM
UV index: 0
Humidity: 57%
via https://ift.tt/2Dtepj7
March 30, 2024 at 10:04AM
The Power of :has() in CSS
Hey all you wonderful developers out there! In this post we are going to explore the use of :has()
in your next web project. :has()
is relatively newish but has gained popularity in the front end community by delivering control over various elements in your UI. Let’s take a look at what the pseudo class is and how we can utilize it.
Syntax
The :has()
CSS pseudo-class helps style an element if any of the things we’re searching for inside it are found and accounted for. It’s like saying, “If there’s something specific inside this box, then style the box this way AND only this way.”
:has(<direct-selector>) {
/* ... */
}
The Styling Problem
In years past we had no way of styling a parent element based on a direct child of that parent with CSS or an element based on another element. In the chance we had to do that, we would need to use some JavaScript and toggle classes on/off based on the structure of the HTML. :has()
solved that problem.
Let’s say that you have a heading level 1 element (h1
) that is the title of a post or something of that nature on a blog list page, and then you have a heading level 2 (h2
) that directly follows it. This h2 could be a sub-heading for the post. If that h2
is present, important, and directly after the h1
, you might want to make that h1 stand out. Before you would have had to write a JS function.
Old School Way – JavaScript
const h1Elements = document.querySelectorAll('h1');
h1Elements.forEach((h1) => {
const h2Sibling = h1.nextElementSibling;
if (h2Sibling && h2Sibling.tagName.toLowerCase() === 'h2') {
h1.classList.add('highlight-content');
}
});
This JS function is looking for all the h1’s that have a h2
proceeding it, and applying a class of highlight-content to make the h1
stand out as an important article.
New and improved with modern day CSS coming in hot! The capabilities of what we can do in the browser have come a long way. We now can take advantage of CSS to do things that we traditionally would have to do with JavaScript, not everything, but some things.
New School Way – CSS
h1:has(+ h2) {
color: blue;
}
Throw Some :has() On It!
Now you can use :has()
to achieve the same thing that the JS function did. This CSS is checking for any h1 and using the sibling combinator checking for an h2 that immediately follows it, and adds the color of blue to the text. Below are a couple use cases of when :has()
can come in handy.
:has Selector Example 1
HTML
<h1>Lorem, ipsum dolor.</h1>
<h2>Lorem ipsum dolor sit amet.</h2>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Eius, odio voluptatibus est vero iste ad?</p>
<h1>Lorem, ipsum dolor.</h1>
<h2>Lorem ipsum dolor sit amet.</h2>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Eius, odio voluptatibus est vero iste ad?</p>
<h1>This is a test</h1>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Eius, odio voluptatibus est vero iste ad?</p>
CSS
h1:has(+ h2) {
color: blue;
}
:has Selector Example 2
A lot of times we as workers on the web are manipulating or working with images. We could be using tools that Cloudinary provides to make use of various transformations on our images, but usually we want to add drop shadows, border-radii, and captions (not to be confused with alternative text in an alt attribute).
The example below is using :has()
to see if a figure or image has a figcaption element and if it does, it applies some background and a border radius to make the image stand out.
HTML
<section>
<figure>
<img src="https://placedog.net/500/280" alt="My aunt sally's dog is a golden retreiver." />
<figcaption>My Aunt Sally's Doggo</figcaption>
</figure>
</section>
CSS
figure:has(figcaption) {
background: #c3baba;
padding: 0.6rem;
max-width: 50%;
border-radius: 5px;
}
Can I :has()
that?
You can see that :has()
has great support across modern browsers.
This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.
Desktop
Chrome | Firefox | IE | Edge | Safari |
---|---|---|---|---|
105 | 121 | No | 105 | 15.4 |
Mobile / Tablet
Android Chrome | Android Firefox | Android | iOS Safari |
---|---|---|---|
122 | 123 | 122 | 15.4 |
:has()
in the Community!
I reached out to my network on Twitter to see how my peers were using :has()
in their day-to-day work and this is what they had to say about it.
svg:has(> #Mail) {
stroke-width: 1;
}
It is great to see how community members are using modern CSS to solve real world problems, and also a shout out to Abbey using it for accessibility reasons!
Things to Keep in Mind
There are a few key points to keep in mind when using :has()
Bullet points referenced from MDN.
- The pseudo-class takes on specificity of the most specific selector in its argument
- If the
:has()
pseudo-class itself is not supported in a browser, the entire selector block will fail unless:has()
is in a forgiving selector list, such as in:is()
and:where()
- The
:has()
pseudo-class cannot be nested within another:has()
- Pseudo-elements are also not valid selectors within
:has()
and pseudo-elements are not valid anchors for:has()
Conclusion
Harnessing the power of CSS, including advanced features like the :has()
pseudo-class, empowers us to craft exceptional web experiences. CSS’s strengths lie in its cascade and specificity…the best part, allowing us to leverage its full potential. By embracing the capabilities of CSS, we can drive web design and development forward, unlocking new possibilities and creating groundbreaking user interfaces.
Links:
- https://ishadeed.com/article/css-has-parent-selector/
- https://css-tricks.com/almanac/selectors/h/has/
- https://developer.chrome.com/blog/has-m105/#forms
- https://css-tricks.com/the-css-has-selector/
The Power of :has() in CSS originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.
from CSS-Tricks https://ift.tt/wnQI80f
via IFTTT
Thursday, March 28, 2024
Mostly Clear today!
With a high of F and a low of 35F. Currently, it's 52F and Clear outside.
Current wind speeds: 11 from the South
Pollen: 0
Sunrise: March 28, 2024 at 06:41PM
Sunset: March 29, 2024 at 07:12AM
UV index: 0
Humidity: 25%
via https://ift.tt/RVHDfFn
March 29, 2024 at 10:03AM
Wednesday, March 27, 2024
Mostly Clear today!
With a high of F and a low of 25F. Currently, it's 38F and Clear outside.
Current wind speeds: 7 from the South
Pollen: 0
Sunrise: March 27, 2024 at 06:42PM
Sunset: March 28, 2024 at 07:11AM
UV index: 0
Humidity: 32%
via https://ift.tt/ED38dig
March 28, 2024 at 10:04AM
Tuesday, March 26, 2024
Snow Early today!
With a high of F and a low of 21F. Currently, it's 28F and Clear outside.
Current wind speeds: 9 from the South
Pollen: 0
Sunrise: March 26, 2024 at 06:44PM
Sunset: March 27, 2024 at 07:10AM
UV index: 0
Humidity: 72%
via https://ift.tt/c68bhKj
March 27, 2024 at 10:03AM
Monday, March 25, 2024
Partly Cloudy today!
With a high of F and a low of 13F. Currently, it's 20F and Partly Cloudy outside.
Current wind speeds: 12 from the Northwest
Pollen: 0
Sunrise: March 25, 2024 at 06:45PM
Sunset: March 26, 2024 at 07:09AM
UV index: 0
Humidity: 73%
via https://ift.tt/HqSlGEZ
March 26, 2024 at 10:04AM
Sunday, March 24, 2024
Rain/Snow/Wind today!
With a high of F and a low of 18F. Currently, it's 30F and Cloudy/Wind outside.
Current wind speeds: 28 from the North
Pollen: 0
Sunrise: March 24, 2024 at 06:47PM
Sunset: March 25, 2024 at 07:08AM
UV index: 0
Humidity: 95%
via https://ift.tt/kHzoAOf
March 25, 2024 at 10:03AM
Saturday, March 23, 2024
Partly Cloudy/Wind today!
With a high of F and a low of 38F. Currently, it's 54F and Partly Cloudy/Wind outside.
Current wind speeds: 20 from the Southeast
Pollen: 0
Sunrise: March 23, 2024 at 06:49PM
Sunset: March 24, 2024 at 07:07AM
UV index: 0
Humidity: 43%
via https://ift.tt/l5b3moE
March 24, 2024 at 10:03AM
Friday, March 22, 2024
Partly Cloudy/Wind today!
With a high of F and a low of 30F. Currently, it's 40F and Clear outside.
Current wind speeds: 15 from the Southeast
Pollen: 0
Sunrise: March 22, 2024 at 06:50PM
Sunset: March 23, 2024 at 07:06AM
UV index: 0
Humidity: 50%
via https://ift.tt/UYW3JrO
March 23, 2024 at 10:03AM
Accessible Forms with Pseudo Classes
Hey all you wonderful developers out there! In this post, I am going to take you through creating a simple contact form using semantic HTML and an awesome CSS pseudo class known as :focus-within
. The :focus-within
class allows for great control over focus and letting your user know this is exactly where they are in the experience. Before we jump in, let’s get to the core of what web accessibility is.
Form Accessibility?
You have most likely heard the term “accessibility” everywhere or the numeronym, a11y. What does it mean? That is a great question with so many answers. When we look at the physical world, accessibility means things like having sharps containers in your bathrooms at your business, making sure there are ramps for wheel assisted people, and having peripherals like large print keyboards on hand for anyone that needs it.
The gamut of accessibility doesn’t stop there, we have digital accessibility that we need to be cognizant of as well, not just for external users, but internal colleagues as well. Color contrast is a low hanging fruit that we should be able to nip in the bud. At our workplaces, making sure that if any employee needs assistive tech like a screen reader, we have that installed and available. There are a lot of things that need to be kept into consideration. This article will focus on web accessibility by keeping the WCAG (web content accessibility guidelines) in mind.
This pseudo class is really great when you want to emphasize that the user is in fact interacting with the element. You can change the background color of the whole form, for example. Or, if focus is moved into an input, you can make the label bold and larger of an input element when focus is moved into that input. What is happening below in the code snippets and examples is what is making the form accessible. :focus-within
is just one way we can use CSS to our advantage.
How To Focus
Focus, in regards to accessibility and the web experience, is the visual indicator that something is being interacted with on the page, in the UI, or within a component. CSS can tell when an interactive element is focused.
Always make sure that the focus indicator or the ring around focusable elements maintains the proper color contrast through the experience.
Focus is written like this and can be styled to match your branding if you choose to style it.
:focus {
* / INSERT STYLES HERE /*
}
Whatever you do, never set your outline to 0
or none
. Doing so will remove a visible focus indicator for everyone across the whole experience. If you need to remove focus, you can, but make sure to add that back in later. When you remove focus from your CSS or set the outline to 0
or none
, it removes the focus ring for all your users. This is seen a lot when using a CSS reset. A CSS reset will reset the styles to a blank canvas. This way you are in charge of the empty canvas to style as you wish. If you wish to use a CSS reset, check out Josh Comeau’s reset.
*DO NOT DO what is below!
:focus {
outline: 0;
}
:focus {
outline: none;
}
Look Within!
One of the coolest ways to style focus using CSS is what this article is all about. If you haven’t checked out the :focus-within
pseudo class, definitely give that a look! There are a lot of hidden gems when it comes to using semantic markup and CSS, and this is one of them. A lot of things that are overlooked are accessible by default, for instance, semantic markup is by default accessible and should be used over div’s at all times.
<header>
<h1>Semantic Markup</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
<section><!-- Code goes here --></section>
<section><!-- Code goes here --></section>
<aside><!-- Code goes here --></aside>
<footer><!-- Code goes here --></footer>
The header
, nav
, main
, section
, aside
, and footer
are all semantic elements. The h1
and ul
are also semantic and accessible.
Unless there is a custom component that needs to be created, then a div
is fine to use, paired with ARIA (Accessible Rich Internet Applications). We can do a deep dive into ARIA in a later post. For now let’s focus…see what I did there…on this CSS pseudo class.
The :focus-within
pseudo class allows you to select an element when any descendent element it contains has focus.
:focus-within
in Action!
HTML
<form>
<div>
<label for="firstName">First Name</label><input id="firstName" type="text">
</div>
<div>
<label for="lastName">Last Name</label><input id="lastName" type="text">
</div>
<div>
<label for="phone">Phone Number</label><input id="phone" type="text">
</div>
<div>
<label for="message">Message</label><textarea id="message"></textarea>
</div>
</form>
CSS
form:focus-within {
background: #ff7300;
color: black;
padding: 10px;
}
The example code above will add a background color of orange, add some padding, and change the color of the labels to black.
The final product looks something like below. Of course the possibilities are endless to change up the styling, but this should get you on a good track to make the web more accessible for everyone!
Another use case for using :focus-within
would be turning the labels bold, a different color, or enlarging them for users with low vision. The example code for that would look something like below.
HTML
<form>
<h1>:focus-within part 2!</h1>
<label for="firstName">First Name: <input name="firstName" type="text" /></label>
<label for="lastName">Last Name: <input name="lastName" type="text" /></label>
<label for="phone">Phone number: <input type="tel" id="phone" /></label>
<label for="message">Message: <textarea name="message" id="message"/></textarea></label>
</form>
CSS
label {
display: block;
margin-right: 10px;
padding-bottom: 15px;
}
label:focus-within {
font-weight: bold;
color: red;
font-size: 1.6em;
}
:focus-within
also has great browser support across the board according to Can I use.
Conclusion
Creating amazing, accessible user experience should always be a top priority when shipping software, not just externally but internally as well. We as developers, all the way up to senior leadership need to be cognizant of the challenges others face and how we can be ambassadors for the web platform to make it a better place.
Using technology like semantic markup and CSS to create inclusive spaces is a crucial part in making the web a better place, let’s continue moving forward and changing lives.
Check out another great resource here on CSS-Tricks on using :focus-within.
Accessible Forms with Pseudo Classes originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.
from CSS-Tricks https://ift.tt/n6oxJXL
via IFTTT
Thursday, March 21, 2024
Partly Cloudy today!
With a high of F and a low of 31F. Currently, it's 47F and Clear outside.
Current wind speeds: 8 from the West
Pollen: 0
Sunrise: March 21, 2024 at 06:52PM
Sunset: March 22, 2024 at 07:05AM
UV index: 0
Humidity: 35%
via https://ift.tt/oJFVd3f
March 22, 2024 at 10:03AM
Wednesday, March 20, 2024
Partly Cloudy today!
With a high of F and a low of 34F. Currently, it's 48F and Partly Cloudy outside.
Current wind speeds: 12 from the Southeast
Pollen: 0
Sunrise: March 20, 2024 at 06:54PM
Sunset: March 21, 2024 at 07:04AM
UV index: 0
Humidity: 44%
via https://ift.tt/1i2rTuR
March 21, 2024 at 10:04AM
Tuesday, March 19, 2024
Clear today!
With a high of F and a low of 32F. Currently, it's 44F and Clear outside.
Current wind speeds: 7 from the Southeast
Pollen: 0
Sunrise: March 19, 2024 at 06:55PM
Sunset: March 20, 2024 at 07:03AM
UV index: 0
Humidity: 43%
via https://ift.tt/we3tSjA
March 20, 2024 at 10:04AM
Monday, March 18, 2024
Clear today!
With a high of F and a low of 33F. Currently, it's 42F and Clear outside.
Current wind speeds: 9 from the Southwest
Pollen: 0
Sunrise: March 18, 2024 at 06:57PM
Sunset: March 19, 2024 at 07:02AM
UV index: 0
Humidity: 45%
via https://ift.tt/KidfJUt
March 19, 2024 at 10:03AM
Sunday, March 17, 2024
Clouds Early/Clearing Late today!
With a high of F and a low of 25F. Currently, it's 39F and Partly Cloudy outside.
Current wind speeds: 7 from the Northwest
Pollen: 0
Sunrise: March 17, 2024 at 06:58PM
Sunset: March 18, 2024 at 07:01AM
UV index: 0
Humidity: 50%
via https://ift.tt/MAGTD4Z
March 18, 2024 at 10:04AM
Saturday, March 16, 2024
Partly Cloudy today!
With a high of F and a low of 26F. Currently, it's 39F and Partly Cloudy outside.
Current wind speeds: 4 from the Northeast
Pollen: 0
Sunrise: March 16, 2024 at 07:00PM
Sunset: March 17, 2024 at 07:00AM
UV index: 0
Humidity: 58%
via https://ift.tt/8ERBPI3
March 17, 2024 at 10:03AM
Friday, March 15, 2024
Partly Cloudy today!
With a high of F and a low of 27F. Currently, it's 36F and Partly Cloudy outside.
Current wind speeds: 10 from the Southwest
Pollen: 0
Sunrise: March 15, 2024 at 07:02PM
Sunset: March 16, 2024 at 06:59AM
UV index: 0
Humidity: 79%
via https://ift.tt/Ej82gk0
March 16, 2024 at 10:03AM
Thursday, March 14, 2024
Rain/Snow today!
With a high of F and a low of 28F. Currently, it's 34F and Snow Shower outside.
Current wind speeds: 11 from the Northeast
Pollen: 0
Sunrise: March 14, 2024 at 07:03PM
Sunset: March 15, 2024 at 06:58AM
UV index: 0
Humidity: 86%
via https://ift.tt/YOrPnIt
March 15, 2024 at 10:04AM
Wednesday, March 13, 2024
Rain/Snow Showers Late today!
With a high of F and a low of 32F. Currently, it's 38F and Mostly Cloudy outside.
Current wind speeds: 13 from the Northeast
Pollen: 0
Sunrise: March 13, 2024 at 07:05PM
Sunset: March 14, 2024 at 06:57AM
UV index: 0
Humidity: 88%
via https://ift.tt/arReYOc
March 14, 2024 at 10:03AM
Tuesday, March 12, 2024
Cloudy today!
With a high of F and a low of 33F. Currently, it's 45F and Partly Cloudy outside.
Current wind speeds: 9 from the Southeast
Pollen: 0
Sunrise: March 12, 2024 at 07:06PM
Sunset: March 13, 2024 at 06:56AM
UV index: 0
Humidity: 34%
via https://ift.tt/ZT30GIk
March 13, 2024 at 10:03AM
Monday, March 11, 2024
Partly Cloudy today!
With a high of F and a low of 34F. Currently, it's 42F and Clear outside.
Current wind speeds: 3 from the East
Pollen: 0
Sunrise: March 11, 2024 at 07:08PM
Sunset: March 12, 2024 at 06:55AM
UV index: 0
Humidity: 40%
via https://ift.tt/25kxFn8
March 12, 2024 at 10:04AM
Sunday, March 10, 2024
Clear today!
With a high of F and a low of 29F. Currently, it's 39F and Clear outside.
Current wind speeds: 11 from the South
Pollen: 0
Sunrise: March 10, 2024 at 07:09PM
Sunset: March 11, 2024 at 06:54AM
UV index: 0
Humidity: 30%
via https://ift.tt/HGZBmwr
March 11, 2024 at 10:03AM
Saturday, March 9, 2024
Clear today!
With a high of F and a low of 26F. Currently, it's 32F and Clear outside.
Current wind speeds: 8 from the South
Pollen: 0
Sunrise: March 9, 2024 at 07:11PM
Sunset: March 10, 2024 at 06:53AM
UV index: 0
Humidity: 44%
via https://ift.tt/Pzd2SsE
March 10, 2024 at 10:04AM
Friday, March 8, 2024
Partly Cloudy today!
With a high of F and a low of 19F. Currently, it's 18F and Clear outside.
Current wind speeds: 8 from the Northwest
Pollen: 0
Sunrise: March 8, 2024 at 07:13PM
Sunset: March 9, 2024 at 06:52AM
UV index: 0
Humidity: 99%
via https://ift.tt/Ps5TnIq
March 9, 2024 at 10:03AM
Thursday, March 7, 2024
Snow Showers Late today!
With a high of F and a low of 21F. Currently, it's 27F and Cloudy outside.
Current wind speeds: 13 from the North
Pollen: 0
Sunrise: March 7, 2024 at 07:14PM
Sunset: March 8, 2024 at 06:50AM
UV index: 0
Humidity: 96%
via https://ift.tt/VsFj1ZL
March 8, 2024 at 10:03AM
Wednesday, March 6, 2024
Snow Showers Late today!
With a high of F and a low of 31F. Currently, it's 47F and Partly Cloudy outside.
Current wind speeds: 8 from the Southeast
Pollen: 0
Sunrise: March 6, 2024 at 07:16PM
Sunset: March 7, 2024 at 06:49AM
UV index: 0
Humidity: 34%
via https://ift.tt/s84hrDF
March 7, 2024 at 10:03AM
Tuesday, March 5, 2024
Partly Cloudy today!
With a high of F and a low of 27F. Currently, it's 35F and Mostly Cloudy outside.
Current wind speeds: 12 from the Southeast
Pollen: 0
Sunrise: March 5, 2024 at 07:17PM
Sunset: March 6, 2024 at 06:48AM
UV index: 0
Humidity: 57%
via https://ift.tt/DnsqNlf
March 6, 2024 at 10:04AM
Monday, March 4, 2024
Mostly Clear today!
With a high of F and a low of 20F. Currently, it's 31F and Clear outside.
Current wind speeds: 8 from the Southeast
Pollen: 0
Sunrise: March 4, 2024 at 07:19PM
Sunset: March 5, 2024 at 06:47AM
UV index: 0
Humidity: 40%
via https://ift.tt/z0w6QAX
March 5, 2024 at 10:04AM
Sunday, March 3, 2024
Partly Cloudy today!
With a high of F and a low of 24F. Currently, it's 40F and Clear outside.
Current wind speeds: 10 from the Northeast
Pollen: 0
Sunrise: March 3, 2024 at 07:20PM
Sunset: March 4, 2024 at 06:46AM
UV index: 0
Humidity: 37%
via https://ift.tt/DUSqRQ8
March 4, 2024 at 10:03AM
Saturday, March 2, 2024
Clear/Wind today!
With a high of F and a low of 32F. Currently, it's 51F and Clear outside.
Current wind speeds: 15 from the Southwest
Pollen: 0
Sunrise: March 2, 2024 at 07:22PM
Sunset: March 3, 2024 at 06:45AM
UV index: 0
Humidity: 17%
via https://ift.tt/e0po659
March 3, 2024 at 10:03AM
Friday, March 1, 2024
Clear today!
With a high of F and a low of 35F. Currently, it's 46F and Clear outside.
Current wind speeds: 9 from the Southwest
Pollen: 0
Sunrise: March 1, 2024 at 07:23PM
Sunset: March 2, 2024 at 06:44AM
UV index: 0
Humidity: 25%
via https://ift.tt/mRJCE39
March 2, 2024 at 10:03AM
Mostly Clear today!
With a high of F and a low of 15F. Currently, it's 14F and Clear outside. Current wind speeds: 13 from the Southwest Pollen: 0 S...
-
So you want an auto-playing looping video without sound? In popular vernacular this is the very meaning of the word GIF . The word has stuck...
-
With a high of F and a low of 31F. Currently, it's 37F and Cloudy outside. Current wind speeds: 7 from the Northeast Pollen: 0 S...
-
Last year , we kicked out a roundup of published surveys, research, and other findings from around the web. There were some nice nuggets in ...