Home Web Front-end CSS Tutorial Designing Better Tables: Using Popovers for Extra Data

Designing Better Tables: Using Popovers for Extra Data

Nov 04, 2024 am 06:18 AM

When working with large data tables, displaying all available information at once can often make the table overwhelming and hard to read. As a result, it’s common to hide secondary information and use a design pattern to reveal more details only when needed.

Data table design is central to good user experience (UX), especially when handling high-volume or complex data. According to articles like Why does table design UX matter? and Design better data tables, there’s a consensus on three main ways to manage these hidden details:

  • Expandable Rows – Expands table rows inline to reveal additional details.
  • Modal Views – Opens a modal dialog with more in-depth information.
  • Quick View (Sidebar) – Displays extra details in a sidebar that can slide in from the edge.

In this article, I’ll show you how to set up these three options flexibly, so you can switch between them without needing to rewrite the table’s markup.

For this, we’ll use popovers, which are ideal for easily attaching information directly to specific rows.


Setting Up the Basic Table

To start, we’ll use the same markup and styles as in A Guide to Styling Tables:

Designing Better Tables: Using Popovers for Extra Data

In the last cell, after the text content, we’ve added a simple button (the icon is from tabler), that will trigger a popover:

<button type="button" popovertarget="p1"></button>
Copy after login
Copy after login

Next, we add the popover somewhere in the document to display the additional content when triggered:

<div id="p1" popover>
  ... content ...   
</div>
Copy after login
Copy after login

Styling the Popover

For the popover styling, we’ll use the template from Adam Argyle’s Steal this popover code. This template includes smooth transitions for the popover’s appearance and disappearance:

.selector {
  &, &::backdrop {
    transition: 
      display .5s allow-discrete, 
      overlay .5s allow-discrete, 
      inset .5s,
      scale .5s,
      opacity .5s;
    opacity: 0;
  }

  &::backdrop {
    background: #0002;
  }

  &:popover-open {
    opacity: 1;
    &::backdrop {
      opacity: 0.5;
    }
  }

  @starting-style {
    &:popover-open,
    &:popover-open::backdrop {
      opacity: 0;
    }
  }
}
Copy after login
Copy after login

Modal View

For the modal layout, we’ll add a --modal modifier class to define the modal’s size and center it on the screen:

&.--modal {
  block-size: calc(100dvh - 2em);
  inline-size: calc(100dvw - 2em);
  inset-block-start: 1em;
  inset-inline: 1em;
  transform-origin: 50% 50%;

  @starting-style {
    &:popover-open{
      scale: 0;
    }
  }
}
Copy after login
Copy after login

Designing Better Tables: Using Popovers for Extra Data


Quick View (Sidebar)

To create a quick view sidebar, we'll add a new modifier class, --inline-start, to the popover. This sidebar slides in from the side of the viewport and can be closed with a smooth animation. Here’s the setup:

&.--inline-start {
  --width: clamp(220px, 33vw, 350px);
  block-size: calc(100dvh - 2em);
  inline-size: var(--width);
  inset-block-start: 1em;
  inset-inline: 1em;

  @starting-style {
    &:popover-open {
      inset-inline: calc(0px - var(--width));
    }
  }
  &[popover]:not(:popover-open) { 
    inset-inline: calc(0px - var(--ui-width));
  }
}
Copy after login

With this setup, the popover slides in from the left. The line &[popover]:not(:popover-open) ensures that it slides back out when closed.

Designing Better Tables: Using Popovers for Extra Data

We can apply similar adjustments to create slide-in effects from the right or from above and below:

Inline End (--inline-end)

Designing Better Tables: Using Popovers for Extra Data

Block End (--block-end)

Designing Better Tables: Using Popovers for Extra Data


Expandable Rows

And finally, let’s look at expandable rows. Unlike modals and sidebars, expandable rows integrate directly within the table layout. Traditionally, this approach involves a hidden with a spanning all columns, and a JavaScript function to toggle its visibility.

But can we reuse the existing popover to expand rows inline? Not directly — but we can fake it by positioning the popover to appear just below the row, creating a similar effect.


First, we attach the popover to the bottom left of the table row by setting anchor-name on the and applying the following CSS:

<button type="button" popovertarget="p1"></button>
Copy after login
Copy after login

Next, we need two features that, unfortunately, are currently Chrome-only:

<div id="p1" popover>
  ... content ...   
</div>
Copy after login
Copy after login

The interpolate-size property allows the popover to animate smoothly to its final height, while anchor-size lets it match the row’s width (or height, using anchor-size(height)).

Designing Better Tables: Using Popovers for Extra Data

So far, so good — but the expanded row covers the next rows.

We can fix this by adding the popover height to the padding-block-end of the table cells within the expanded row:

Designing Better Tables: Using Popovers for Extra Data

Cool. The illusion is complete!

To animate the height, we'll add a few extra declarations to the CSS:

.selector {
  &, &::backdrop {
    transition: 
      display .5s allow-discrete, 
      overlay .5s allow-discrete, 
      inset .5s,
      scale .5s,
      opacity .5s;
    opacity: 0;
  }

  &::backdrop {
    background: #0002;
  }

  &:popover-open {
    opacity: 1;
    &::backdrop {
      opacity: 0.5;
    }
  }

  @starting-style {
    &:popover-open,
    &:popover-open::backdrop {
      opacity: 0;
    }
  }
}
Copy after login
Copy after login

Automating the Padding Adjustment

To avoid manually updating padding, we can use a script that dynamically updates the padding based on the popover’s height:

&.--modal {
  block-size: calc(100dvh - 2em);
  inline-size: calc(100dvw - 2em);
  inset-block-start: 1em;
  inset-inline: 1em;
  transform-origin: 50% 50%;

  @starting-style {
    &:popover-open{
      scale: 0;
    }
  }
}
Copy after login
Copy after login

This script listens for the popover’s toggle event, dynamically updating a custom property, --row, to match the popover height when open.


Demo

You can view a demo at browser.style/ui/table-expand, where you’ll also find the original table demo styles.

The above is the detailed content of Designing Better Tables: Using Popovers for Extra Data. 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.

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.

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:

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.

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?

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

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles