Smashing Magazine - #329: Useful CSS Techniques

With unusual CSS issues, from scrolling chaining to text-based UIs to glitchy hover effects. Issue #329 November 30, 2021 View in the browser 💨

Smashing Newsletter

Dear Smashing Friends,

Good ol’ CSS! It might seem that CSS is quite simple, with a few style declarations here and there, and a few styles to layout components on the page. However, when it comes to micro-interactions and scalability, CSS often isn’t easy to tame.

In this newsletter, we look into some of the unusual issues when using CSS, and how we can solve them for good — from hover glitches to better CSS shadows, all the way to scrolling chaining. We hope you’ll find some useful nuggets in here.

On another note, do you have anything planned for next Monday? We’d love to welcome you to another session of Smashing Meets on Dec. 6, 2021 where we’ll all be discussing all things accessibility together with Christopher Patnoe, Harris Schneiderman, Manuel Matuzović, and yours truly.

The Smashing Meets For All
Join us in a free live event on front-end accessibility with sessions on how to design and develop your digital products in an accessible way.

For those of you screaming for more, please mark your calendars for A Smashing Hour with Henri Helvetica on Dec. 15, 2021 where we’ll be chatting about what’s happening on the web, especially in terms of performance.

We also have our ongoing front-end workshops, or even join us at the in-person SmashingConf SF 2022 that’s going to take place on March 28–31, 2022. Wherever it is that we meet, it’ll be a great pleasure to see you there!

— Vitaly


1. A CSS Library For Text-Based UIs

If you have a sweet spot for MS-DOS-like UIs, well, good news, Vinicius Reif Biavatti created TuiCss, a CSS components library that is bound to wake some sweet memories. Based on the good ol’ ASCII table, it uses ultra-contrast colors and reduced effects to create the retro effect.

TuiCss

Don’t let the retro look fool you, though: The library has everything you might need to create modern UIs — radio buttons, dropdowns, input, navbars, panels, and much more. A grid enables you to create responsive designs, of course, and, if you’re feeling nostalgic, a table grid is included, too. A beautiful combination of old and new. (cm)


2. Creating Realistic CSS Shadows

Creating lush, realistic CSS shadows can be quite a challenge. One of the tricks to create shadows that feel more natural than what you typically see comes from Josh W Comeau. He recommends to stack 5 or 6 individual shadow layers and customize each one of them with different values for x/y offset, blur radius, spread, color, and opacity. So far so good, but which values should you use for all those settings? Josh’s Shadow Palette Generator helps you figure it out, without worrying about the hard numbers.

Shadow Palette Generator

The Shadow Palette Generator functions at a more abstract level than similar tools. So instead of fiddling with precise values, you can focus on the “feel” of the shadow instead. Do you want it to be deep and prominent, or light and subtle? And should it be tight and crispy, or soft and blurry? The sliders help you find the sweet spot.

To give you maximum control over how elevated you want an element to appear, the generator outputs a set of three cohesive shadows instead of a single one, with each one of them representing different elevations. The output uses CSS Custom Properties by the way, so you can easily reuse the shadows throughout your application. One for the bookmarks. (cm)


From our sponsor

The Future Of Design Feedback

The Future Of Design Feedback
Cut through the noise with immediate, visual feedback. Go from design to build to publish without losing your mind in the process. The best part... it’s free.


3. Improving Scrolling Performance

One line of CSS to make Google’s data grid scroll 10x faster? Sounds too good to be true? Well, Johan Isaksson did just that. Frustrated by major scroll lag when displaying a larger dataset in Google Search Console to see which external websites link to his site, Johan decided to get to the root of the issue.

Google Search Console

Clicking around on the Elements panel in DevTools, Johan found 16,000+ DOM elements that are used to display just 500 rows of information, all of them laid out when you scroll the grid. To fix the issue, Johan added contain: strict to the <table> on the Elements panel, specifying that it will not affect the layout or style of other elements on the page. The result is a major performance improvement: Scrolling reached almost 60 FPS instead of 6–7. A fantastic example of how powerful CSS is. (cm)


4. Upcoming Front-End & UX Workshops

You might have heard it: we run online workshops around front-end and design, be it accessibility, performance, navigation, or landing pages. In fact, we have a couple of workshops coming up soon, and we thought that, you know, you might want to join in as well.

Smashing Online Events
Front-end and design can sometimes feel like you’re riding some pretty wild waves! We’ve got your back with personal and inclusive events.

As always, here’s an overview of our upcoming workshops:


5. Smoother Hover Effects

We’ve all come across a button that shows a weird flickering glitch when you hover over it instead of a smooth animation effect. Eric Wätke shares a handy little tip to prevent this from happening: Put all the styles you want to animate on hover in a pseudo-element, not in the element itself.

Hover effect with pseudo-elements

As Eric points out, this not only prevents hover glitches but it also looks better. The technique works with regular hover animations but also with boop animations. By the way, if you haven’t heard of boop animations yet, be sure to check out Josh W Comeau’s article. He describes how to create a hover effect that “flicks” the element without permanently changing its rotation to create a dynamic and surprising effect. (cm)


From our sponsor

Invest In Your Career: Get 25% Off UX Design Courses

Invest In Your Career With The Interaction Design Foundation
Hurry, this offer ends at Midnight. Sign up now!


6. Handy CSS Pseudo-Classes

Pseudo-classes make it possible to apply styling to an element in relation to external factors like the status of its content, the position of the mouse, or the history of the navigator. And, well, there are quite a lot of pseudo-classes out there. Stefan Judis collected some interesting ones that you might not have heard of yet in a Twitter thread.

Handy CSS Pseudo-Classes

:autofill, for example, matches when an <input> element has its value autofilled by the browser and stops matching if the user edits the field. :default selects form elements that are the default in a group of related elements. And :fullscreen lets you automatically adjust the size, style, or layout of content when elements switch back and forth between full-screen and traditional presentations. For more handy pseudo-classes, be sure to check out Stefan’s thread or take a look at the MDN Web Docs. (cm)


7. Preventing Scroll Chaining

Imagine you have an element with position: fixed. A modal dialog that is positioned in the center of the viewport, for example, with the actual web page content underneath it. Now, if the modal has scrolling and you have reached its bottom boundary, the browser will continue scrolling on the main page’s content. It’s the default behavior and, unfortunately, quite confusing. Luckily, scroll chaining, as the unwanted effect is called, can be fixed with CSS. The magic ingredient: overscroll-behavior.

Prevent Scroll Chaining With Overscroll Behavior

If you aren’t familiar with the overscroll-behavior property yet, Ahmad Shadeed summarized everything you need to know about it and, of course, how to use it to prevent scroll chaining. Possible use cases are not only modals but also mobile navigation with long lists, side navigation, chat components, and horizontal lists. A useful property that elegantly solves an issue that required quite some hacking around years ago. (cm)


From our sponsor

Build In-Demand Skills In Northwestern’s Online MS In Information Design And Strategy

Work at the Intersection of Data, Design and Technology. Earn your master’s degree online at Northwestern Information Design and Strategy.
Earn your master’s degree online.


8. Line Wrap Balancer, Remastered

Web browsers follow a simple pattern when it comes to laying out text: one word after the other, and when there’s no more room, words will wrap onto a new line. While this might be a good solution in most cases, it doesn’t guarantee an even distribution of words or prevent a single word from wrapping onto a new line. So if you’re into typographic details like these, there’s no getting around a text balancer. Text balancers help eliminate typographic widows and distribute words more evenly over multiple lines. However, they aren’t perfect either.

Text balancer

Unhappy with the status quo, Daniel Aleksandersen decided to improve the situation and make the open-source New York Times Text Balancer even better. The result is a fast text wrap balancer for multi-line headlines that wraps text more evenly across lines and reduces uneven line lengths. It rebalances text on device orientation changes or when the window or element is resized. If you want to learn more about the changes and improvements that Daniel made, be sure to also check out the accompanying blog post. A handy fallback until browsers will finally support CSS text-wrap: balance. (cm)


9. New On Smashing Job Board


10. Recent Smashing Articles


That’s All, Folks!

Thank you so much for reading and for your support in helping us keep the web dev and design community strong with our newsletter. See you next time!


This newsletter issue was written and edited by Cosima Mielke (cm), Vitaly Friedman (vf) and Iris Lješnjanin (il).


Sent to truly smashing readers via Mailchimp.
We sincerely appreciate your kind support. You
rock.

Follow us on Twitter Join us on Facebook

unsubscribe update preferences view in your browser

Older messages

New Smashing Book: “Touch Design for Mobile Interfaces”

Wednesday, November 24, 2021

Meet “Touch Design for Mobile Interfaces”, our brand-new guide on designing for mobile. Written by Steven Hoober. Design for the way people really use their mobile devices. Touch Design for Mobile

#328: Localization & Internationalization

Tuesday, November 23, 2021

With useful internationalization resources for designing and creating digital products for international users. Issue #328 • November 23, 2021 • View in the browser 💨 Smashing Newsletter Dear Smashing

#327: Designing For Mobile and Touch

Tuesday, November 16, 2021

With useful tools for designing better mobile UX, best practices, onboarding UX and mobile UI inspiration. Issue #327 • November 16, 2021 • View in the browser 💨 Smashing Newsletter Dear Smashing

#326: Designing Better Complex UIs

Tuesday, November 9, 2021

With useful techniques for better enterprise tables, modals, sliders, web forms and sounds. Issue #326 • November 9, 2021 • View in the browser 💨 Smashing Newsletter Dear Smashing Friends, There are so

#325: Little Friendly Websites

Tuesday, November 2, 2021

With useful helpers for picking a plant, listening to the music from the past and UX misconceptions and laws. Issue #325 • November 2, 2021 • View in the browser 💨 Smashing Newsletter Tere Smashing

You Might Also Like

Highlighted Text, Generative AI, Cicadas, Devtools Patterns, Serra Case Study

Wednesday, May 8, 2024

The 5 best design links, every day. Curated by a selection of great editors. Email not displaying properly? View browser version. Sidebar May 8 2024 A Brief Note on Highlighted Text adrianroselli.com

The Problem With Using Social Media as Design Education

Tuesday, May 7, 2024

View in your browser | Update your preferences ADPro Image may contain: People, Person, Accessories, Bag, Handbag, Food, Meal, Adult, Clothing, Hat, Glasses, Fun, and Party Twenty-five days were left

#455: CSS

Tuesday, May 7, 2024

CSS Masonry Layout, Self-Modifying CSS Variables and Hanging Punctuation Issue #455 • May 7, 2024 • View in the browser Smashing Newsletter Dobryi vechir Smashing Friends, When I first encountered CSS

🤯 Immersive Admin Dashboard Designs + 🏆 Challenge Updates

Tuesday, May 7, 2024

Stay Up-to-Date With UpLabs' Latest Design News 🎨 Firstly, let's congratulate Rahul Parmar, the winner of our latest 👾 ChatGPT Redesign Challenge! Congratulations!! Secondly, the end of April

Web Components, Conditional Styling, Popover API, color-mix(), Product Designers

Tuesday, May 7, 2024

The 5 best design links, every day. Curated by a selection of great editors. Email not displaying properly? View browser version. Sidebar May 7 2024 Map of the web graph.henryn.ca A visualization of

Map of the Web, JSR Registry, Presidential Campaign a11y, Age of Average, CSS Specificity

Tuesday, May 7, 2024

The 5 best design links, every day. Curated by a selection of great editors. Email not displaying properly? View browser version. Sidebar May 6 2024 Map of the web graph.henryn.ca A visualization of

How we do UX retreats at Balsamiq (+ steal our agenda!)

Monday, May 6, 2024

Inside our UX group retreat ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Accessibility Weekly: #395: Why Are My Live Regions Not Working?

Monday, May 6, 2024

May 6, 2024 • Issue #395 View this issue online or browse the full issue archive. Featured: Why are my live regions not working? "Live regions have a reputation for being "flaky" and

Writing a POV Doc

Sunday, May 5, 2024

Issue 193: Share what you care about at scale ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

It's Officially Show House Season

Thursday, May 2, 2024

View in your browser | Update your preferences ADPro Showing Up, and Showing Off One of the traditions design aficionados look forward to the most each year is the return of decorator show houses. In