Table of Contents
Some text
Scrolling status in container query!
Home Web Front-end CSS Tutorial Chrome 133 Goodies

Chrome 133 Goodies

Mar 07, 2025 pm 04:43 PM

Chrome 133 Goodies

The Chrome team's work must be exciting! Getting first-hand at the latest browser version and making cool demos to show off new features must feel great. Of course, I don't envy it at all! (You ask why?)

Back to the point, have you seen the release notes of Chrome 133? It is currently in beta, but the Chrome team has released a series of great new articles and impressive demos that are hard to ignore. I decided to put them together.

attr() Widely used functions!

We have been able to use HTML attributes in CSS for a while, but it is limited to content attributes and parses only strings.

<h1 id="Some-text">Some text</h1>
Copy after login
Copy after login
h1::before {
  content: ' (Color: ' attr(data-color) ') ';
}
Copy after login
Copy after login

Bramus shows how to use it in Chrome 133 for any CSS attribute, including custom attributes. For example, we can get the value of the attribute and use it for the color attribute of the element:

h1 {
  color: attr(data-color type(<color>), https://www.php.cn/link/93ac0c50dd620dc7b88e5fe05c70e15bfff)
}</color>
Copy after login
Copy after login

Of course, this is a simple example. But it shows that there are three components here:

  1. Properties (data-color)
  2. Type (type())
  3. Arbitrage value (https://www.php.cn/link/93ac0c50dd620dc7b88e5fe05c70e15bffff)

Attributes are defined by ourselves. It is very convenient to be able to insert wildcards into tags and use them for style settings. type() is a new feature that helps CSS identify the type of value being processed. If we are using numeric values, we can use a more concise writing method. For example, suppose we use attributes to set the font size of an element:

<div data-size="20">Some text</div>
Copy after login
Copy after login

Now we can set the font-size attribute (unit in px):

h1 {
  font-size: attr(data-size px, 16);
}
Copy after login
Copy after login

Arbitrage values ​​are optional and may not be required depending on your use case.

Scrolling status in container query!

This is amazing! If you ever wanted a way to style the sticky element when it is in a "sticky" state, you'll know how cool it is to have such a feature. Adam Argyle uses the classic pattern of the alphabetical list and applies styles to the letter title when it is pasted to the top of the viewport. The same is true for scrolling snap elements and scrolling container elements.

In other words, when the elements are "stick", "snap", and "scrollable", we can style them.

A small example you need to open in the Chromium browser:

The overall idea (I only know so much now) is that we register a container...a container we can query. We set a container-type for the container, which is the scroll type we are using. In this case, we use sticky positioning where the element is "paste" to the top of the page.

<h1 id="Some-text">Some text</h1>
Copy after login
Copy after login

The container cannot query itself, so it basically has to be a wrapper for the elements we want to paste. The menu is a little special because we have the <nav></nav> element, which is usually populated with an unordered link list. So our <nav></nav> can be used as a container for our query, because we are actually pasting the unordered list to the top of the page.

h1::before {
  content: ' (Color: ' attr(data-color) ') ';
}
Copy after login
Copy after login

We can put the sticky logic directly on <nav></nav> because it actually contains the pasted content:

h1 {
  color: attr(data-color type(<color>), https://www.php.cn/link/93ac0c50dd620dc7b88e5fe05c70e15bfff)
}</color>
Copy after login
Copy after login

If we are using a sticky footer instead of a menu, we can use stuck: bottom. But the point is that once the <nav></nav> element is pasted to the top, we can apply styles to it in the @container block as follows:

<div data-size="20">Some text</div>
Copy after login
Copy after login

Nesting other selectors in it seems to work as well. For example, when the navigation is sticky, we can change the link in the menu:

h1 {
  font-size: attr(data-size px, 16);
}
Copy after login
Copy after login

So, yes. As I said, being part of the Chrome development team, it must be cool to get started with these features. Thank you very much to Bramus and Adam for continuing to introduce us to new features and the great effort to make such a great demo.

The above is the detailed content of Chrome 133 Goodies. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

How to Use CSS Grid for Sticky Headers and Footers How to Use CSS Grid for Sticky Headers and Footers Apr 02, 2025 pm 06:29 PM

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there&#039;s a bit of a learning curve, but Grid is

Google Fonts   Variable Fonts Google Fonts Variable Fonts Apr 09, 2025 am 10:42 AM

I see Google Fonts rolled out a new design (Tweet). Compared to the last big redesign, this feels much more iterative. I can barely tell the difference

See all articles