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

推荐订阅源

Martin Fowler
Martin Fowler
L
LINUX DO - 最新话题
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Visual Studio Blog
O
OpenAI News
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
Spread Privacy
Spread Privacy
Y
Y Combinator Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
T
The Blog of Author Tim Ferriss
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
Project Zero
Project Zero
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
G
Google Developers Blog

Defensive CSS

Defensive CSS - Button minimum width Defensive CSS - Input zoom on iOS Safari Defensive CSS - Default flexbox stretching Defensive CSS - Image inner border Defensive CSS - Accidental hover on mobile Defensive CSS - Vertical media queries Defensive CSS - Text over image Defensive CSS - Using space-between Defensive CSS - Scrollbars on demand Defensive CSS - Scrollbar gutter Defensive CSS - Scroll chaining Defensive CSS - Position sticky with CSS Grid Defensive CSS - Image maximum width Defensive CSS - Grouping vendor selectors Defensive CSS - Minimum Content Size In CSS grid Defensive CSS - Minimum Content Size In CSS Flexbox Defensive CSS - Fixed sizes Defensive CSS - CSS Variable Fallback Defensive CSS - CSS grid fixed values Defensive CSS - Background repeat Defensive CSS - Auto-fit Vs Auto-fill Defensive CSS - Long Content Defensive CSS - Image Distortion Defensive CSS - Flexbox Wrapping
Defensive CSS - Component Spacing
2022-04-19 · via Defensive CSS

We developers need to account for different content lengths. That means, spacing should be added to a component, even though it seems like not needed.

In this example, we have a section title and an action button on the right side. Currently, it looks okay. But let’s see what happens when the title is longer.

Notice how the text is too close to the action button? You might be thinking about multi-line wrapping, but I will come to that in another section. For now, let’s focus on the spacing.

If the title has spacing and text truncation, we won’t see such an issue.

.section__title {
margin-right: 1rem;
}

Examples and use cases

Spacing

This is similar to the long content tip, but in that case we don't want to truncate the text since the user must read it all. One little thing here is to account for spacing even though the content we've currently isn't long.

Consider the following demo. We have a short title and everything works like a charm.

However, when the content is too long, the title should have 16px margin from the "more" button. Accounting for that ahead of time is important to avoid the text to collide with the button.

The pink outline represent the text element. When you click the "toggle defensive" checkbox, a 16px spacing will be added.