惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
IT之家
IT之家
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
W
WeLiveSecurity
B
Blog RSS Feed
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
S
Security @ Cisco Blogs
博客园 - 叶小钗
月光博客
月光博客
Webroot Blog
Webroot Blog
H
Hacker News: Front Page
N
News and Events Feed by Topic
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Help Net Security
Help Net Security
S
Secure Thoughts
SecWiki News
SecWiki News
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
S
Schneier on Security
A
Arctic Wolf
博客园 - 司徒正美
T
Tor Project blog
T
Tenable Blog
量子位
D
DataBreaches.Net
PCI Perspectives
PCI Perspectives
T
The Exploit Database - CXSecurity.com
T
Threatpost
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
Cloudbric
Cloudbric
T
The Blog of Author Tim Ferriss
N
News | PayPal Newsroom
Project Zero
Project Zero
S
Securelist
Forbes - Security
Forbes - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
L
LINUX DO - 热门话题
Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
C
Cisco Blogs
V
V2EX
P
Privacy & Cybersecurity Law Blog
Cisco Talos Blog
Cisco Talos Blog

Ahmad Shadeed

Better fluid sizing with round() Use Cases for Field Sizing The Basics of Anchor Positioning Item Flow CSS Relative Colors Balancing Text In CSS Should masonry be part of CSS grid? CSS display contents CSS Grid Areas CSS Cap Unit An Interactive Guide to CSS Container Queries CSS :has() Interactive Guide CSS Nesting Future CSS: State Container Queries Rebuilding a comment component with modern CSS Conditional CSS with :has and :nth-last-child CSS Text balancing with text-wrap:balance CSS Masking Do we need CSS flex-wrap detection? My CSS Wishlist Conditional CSS CSS Style Queries Inside the mind of a frontend developer: Article layout Inside the mind of a frontend developer: Hero section CSS container queries are finally here The CSS behind Figma First Look At The CSS object-view-box Property Learn CSS Subgrid CSS :has Parent Selector Aligning Content In Different Wrappers Flexbox Dynamic Line Separator Hello, CSS Cascade Layers Building UI Components With SVG and CSS A Deep CSS Dive Into Radial And Conic Gradients Defensive CSS Building Real-life Components: Facebook Messenger Conditional Border Radius In CSS CSS Container Query Units Less Absolute Positioning With Modern CSS Aligning a Button Label Vertically Comparing Design Mockups To Code Result Using HSL Colors In CSS Custom Scrollbars In CSS Let CSS Container Queries For Designers The State of CSS Cross-Browser Development Overflow Issues In CSS Inspect Element As A Way To Increase Your Curiosity Handling Text Over Images in CSS Digging Into CSS Logical Properties Clipping Scrollable Areas On The inline-start Side Understanding Clip Path in CSS The Art of Building Real-life Components Handling Short And Long Content In CSS CSS Scroll Snap A Deep Dive Into CSS Grid minmax() CSS Variables 101 Finding The Root Cause of a CSS Bug Learn CSS centering How to detect browser support for Flexbox Gap CSS Mistakes While On Autopilot Digging Into the Flex Property Understanding CSS Multiple Backgrounds Aligning Logo Images in CSS Grid for layout, Flexbox for components Colors in CSS Thinking About The In-between Design Cases min(), max(), and clamp() CSS Functions Image Techniques On The Web Everything About Auto in CSS Learn Box Alignment Let Learn CSS Positioning Intrinsic Sizing In CSS CSS Grid Template Areas In Action Hiding Elements On The Web Creating a Variable Color Font From Scratch Building a Football Ticket With CSS and SVG Blending Modes in CSS CSS Variables With Inline Styles Implementing Dark Mode For My Website Rebuilding Apple Music Header in HTML & CSS Accessible Checkbox Layout Flickering On Browser Resize Enhancing The Clickable Area Size Custom Underlines with SVG Part 3: The Process of Implementing A UI Design From Scratch Part 2: The Process of Implementing A UI Design From Scratch Building An Old Nav Design CSS Flexbox: 5 Real World Use Cases I Used CSS Inline Flex For The First Time The Process of Implementing A UI Design From Scratch Common CSS Issues For Front-End Projects Handling Long and Unexpected Content in CSS How to Build Web Form Layouts With CSS Grid Grid Layout Ah-ha Moment Enhancing Our Components with CSS :empty Building Resizeable Components with Relative CSS Units CSS Writing Mode The Journey of Learning Front End Web Development on a Daily Basis
CSS Nesting UX in DevTools
Ahmad Shadeed · 2023-11-19 · via Ahmad Shadeed

The Layout Maestro

I spent years teaching CSS layout on this blog. I put everything I know into The Layout Maestro course: 70+ lessons and 150+ interactive examples that teach you how to think CSS layouts, not just memorize syntax.

Get the course

While documenting my learning about CSS nesting, I wasn’t a big fan of how the nesting is shown in the DevTools. It’s inconsistent between browsers, and thought why not suggest a few solutions to this problem?

In this article, I will share my thinking process of solving the nesting UX in DevTools, alongside the root problem and why I did that in the first place.

Introduction

First, I want to make sure that you know that CSS nesting is a new feature that was supported early this year. It might be a bit early to judge the current DevTools UX, but I need to do it for my exploration and curiosity.

Let’s explore an example and see how the nesting is shown in different browsers:

What’s your favorite? For this particular example, I prefer Firefox for the following reasons:

  • It shows the whole nesting, just how I wrote it in CSS.
  • Syntax highlighting is better (notice how the :hover is colored)

But that doesn’t mean that I’m totally happy with Firefox UX.

The problem

As a front-end developer myself, I came from using tools like Sass and PostCSS for nesting. The browser will compile the CSS nesting into a full selector in the browser.

In the current DevTools, the CSS nesting isn’t shown as a full selector. Instead, it mimics how the CSS is written.

Let’s take an example.

.list-item {
  &:last-child {
    /* Styles */
  }
}

We expect that to render in the DevTools as a nested selector, but since it’s native now, it won’t happen.

There should be a way to fix that and make it more clear to see the full selector.

Proposed solutions

For the following solutions, I will explore them based on Chrome UI, but most of them should apply to other browsers as well.

Here is how nesting looks currently:

Let’s explore the solutions.

Proposal 1: Expand or collapse the nesting

The first idea that I thought about is to show the compiled CSS nesting by default, and the ability to expand or collapse it in the DevTools.

Here is what it looks like:

When expanded, it will show the full rule set, just as written in the code editor. If there are multiple nested rules, it will accommodate that:

Pros

  • Helps to show the full selector without trying to guess how it’s compiled.
  • Saves space in the styles tab.

Cons

  • Adding the arrow might not align with the design guidelines. In other words, it’s a big change to the UI, which might require the rework of certain UI elements.

Proposal 2: Expand or collapse the nesting + inline arrow

What I mean by “inline arrow” is to place the expand/collapse arrow in a different place.

This can save up space, and make the arrow more related to the context.

Here is the proposal:

Same as proposal 1, but with the arrow positioning concern fixed.

Proposal 3: Nesting badge

We can display a badge that represents nesting. The icon isn’t the best, but you got the idea.

When the badge is active, it will show the full nested CSS.

Pros

  • The user can quickly know that this is a nested rule.
  • The toggle action is a known pattern. For example, the “grid” badge activates the layout of the grid, the nested badge shows the actual nested CSS.

Cons

  • The button will change its position when toggled

Proposal 4: Show nested CSS on hover

From a UI perspective, this is similar to the previous proposal, but instead of toggling, it can show the nested CSS on hover.

Here is how it looks with a long selector:

It can get even more crazy. I’m not a fan of this, but it’s an idea that is worth exploring.

What do you think? Which of the proposals do you find interesting?

What should happen when copying a nested rule set?

Currently, when copying a selector, there are different behaviour that I noticed.

Chrome DevTools

When I select and copy the CSS rule set, the pasted result is broken. I tried that with a complex nesting to intentionally break it.

Here is the CSS in the code editor.

form {
  & label {
    &:first-child {
      &:after {
        content: "test";
      }
    }
  }
}

Here is a figure that shows the pasted result:

I filed a bug here.

Firefox DevTools

It’s just what I expected.

Safari DevTools

Same as Chrome. I have to add code brackets for each nested block.

Aside from the bug in Chrome, I’m thinking about providing the user with two options:

  • Copy the rule set as as.
  • Copy the full CSS nested selector

This can be useful in cases where you want to copy nested CSS and paste it back into the code editor.

Since the CSS nesting is new, using it isn’t an option now for a lot of developers. The good thing is that you can use Sass, for example, and copy the nested CSS from the DevTools.

Outro

To wrap up, thinking about how the browser DevTools should address CSS nesting is an important step to take. It will help to make the CSS nesting more approachable and easier to debug and use by developers.

Again, I would love to hear your feedback, and if you work at browser vendors, I will be happy to help and contribute where I can.