GAZAR

Principal Engineer | Mentor

Reviewing Inset, Popover, and :has() in CSS - New Features

Reviewing Inset, Popover, and :has() in CSS - New Features

Exploring deeper into the realm of CSS offers a myriad of possibilities for enhancing the visual appeal and interactivity of web elements. In this article, we'll unravel the magic behind CSS properties such as inset, popover, and the :has() pseudo-class selector, accompanied by illustrative examples.

Inset

The inset property allows for precise control over the positioning of elements within their containing elements. It defines the distance between the edges of an element and the edges of its containing block. Let's see how it works in practice:

.box {
  width: 200px;
  height: 100px;
  background-color: #f0f0f0;
  inset: 20px 40px 60px 80px; /* top, right, bottom, left */
}

This one is easy, we needed it anyway! top, right, bottom, left;

Popover

Popovers are interactive overlays that provide additional information or functionality when triggered by user actions. CSS enables the creation of visually appealing popovers to enhance user experience. Let's implement a simple popover:

<button popovertarget="mypopover">
      Toggle the popover
      <div id="mypopover" popover>Popover content</div>
</button>
[popover] {
  background-color: red;
  color: white;
}

:popover-open {
  width: fit-content;
  height: fit-content;
}

[CodeSandBox]

:has()

The :has() pseudo-class selector allows for styling elements based on their descendants. It selects elements that have at least one descendant that matches the specified selector. Let's see it in action:

.list-item:has(.icon) {
  background-color: #f0f0f0;
}

CSS properties such as inset, selectmenu, popover, and the :has() pseudo-class selector provide powerful tools for crafting visually stunning and interactive web experiences. By mastering these properties, you can take your frontend development skills to the next level and create compelling user interfaces that captivate and engage visitors.

CSS properties such as inset, popover, and the :has() pseudo-class selector provide powerful tools for crafting visually stunning and interactive web experiences. By mastering these properties, you can take your frontend development skills to the next level and create compelling user interfaces that captivate and engage visitors.


Comments