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

推荐订阅源

Forbes - Security
Forbes - Security
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
美团技术团队
博客园 - 聂微东
博客园 - 叶小钗
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园_首页
Spread Privacy
Spread Privacy
J
Java Code Geeks
雷峰网
雷峰网
宝玉的分享
宝玉的分享
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Privacy International News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threat Research - Cisco Blogs
The Hacker News
The Hacker News
量子位
L
LINUX DO - 热门话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
GRAHAM CLULEY
D
Darknet – Hacking Tools, Hacker News & Cyber Security
月光博客
月光博客
腾讯CDC
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tor Project blog
罗磊的独立博客
V
Vulnerabilities – Threatpost
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
Project Zero
Project Zero
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tenable Blog
MyScale Blog
MyScale Blog
T
The Exploit Database - CXSecurity.com
GbyAI
GbyAI
博客园 - 【当耐特】
O
OpenAI News
Schneier on Security
Schneier on Security
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Securelist
博客园 - 司徒正美

CSS Wizardry

Front-End’s Missing Metric: The TBT Window Meet Your Users Where They Are with Obs.js Better Browser Caching with No-Vary-Search font-family Doesn’t Fall Back the Way You Think What Is CSS Containment and How Can I Use It? When All You Can Do Is All or Nothing, Do Nothing Obs.js: Context-Aware Web Performance for Everyone Low- and Mid-Tier Mobile for the Real World (2025) The Fastest Site in the Tour de France Making Sense of the Performance Extensibility API Why Do We Have a Cache-Control Request Header? HTML Is Not a Programming Language… Build for the Web, Build on the Web, Build with the Web Licensing Code on CSS Wizardry A Layered Approach to Speculation Rules Designing (and Evolving) a New Web Performance Score Core Web Vitals Colours The Ultimate Contract Templates for Tech Consultants: Protect Your Business and Get Paid Optimising for High Latency Environments Cache Grab: How Much Are You Leaving on the Table? blocking=render: Why would you do that?! Correctly Configure (Pre) Connections The Three Cs: 🤝 Concatenate, 🗜️ Compress, 🗳️ Cache What Is the Maximum max-age? How to Clear Cache and Cookies on a Customer’s Device The Ultimate Low-Quality Image Placeholder Technique Core Web Vitals for Search Engine Optimisation: What Do We Need to Know? The HTTP/1-liness of HTTP/2 In Defence of DOM­Content­Loaded Site-Speed Topography Remapped Why Not document.write()? Speeding Up Async Snippets Critical CSS? Not So Fast! Measure What You Impact, Not What You Influence Optimising Largest Contentful Paint Measuring Web Performance in Mobile Safari Site-Speed Topography Speed Up Google Fonts Real-World Effectiveness of Brotli Performance Budgets, Pragmatically Lazy Pre-Browsing with Prefetch Making Cloud.typography Fast(er) Time to First Byte: What It Is and How to Improve It Self-Host Your Static Assets Tips for Technical Interviews Cache-Control for Civilians Bandwidth or Latency: When to Optimise for Which ITCSS × Skillshare What If? CSS and Network Performance The Three Types of Performance Testing Getting to Know a Legacy Codebase Image Inconsistencies: How and When Browsers Download Images Identifying, Auditing, and Discussing Third Parties My Digital Music Setup Measuring the Hard-to-Measure Finding Dead CSS The Fallacies of Distributed Computing (Applied to Front-End Performance) Ten Years Old Relative Requirements Airplanes and Ashtrays Performance and Resilience: Stress-Testing Third Parties Refactoring Tunnels Little Things I Like to Do with Git Writing Tidy Code Configuring Git and Vim Base64 Encoding & Performance, Part 2: Gathering Data Base64 Encoding & Performance, Part 1: What’s Up with Base64? Code Smells in CSS Revisited Typography for Developers Moving CSS Wizardry onto HTTPS and HTTP/2 Ack for CSS Developers A New Year, a New Focus Preparing Vim for Apple’s Touch Bar Choosing the Correct Average CSS Shorthand Syntax Considered an Anti-Pattern CSS Wizardry Newsletter Nesting Your BEM? Improving Perceived Performance with Multiple Background Images Continue Normalising Your CSS Pure CSS Content Filter Pragmatic, Practical, and Progressive Theming with Custom Properties Refactoring CSS: The Three I’s Speaker’s Checklist: Before and After Your Talk Improving Your CSS with Parker The Importance of !important: Forcing Immutability in CSS Mixins Better for Performance Managing Typography on Large Apps White October Events Workshop Partnership BEMIT: Taking the BEM Naming Convention a Step Further Travelling Like You Want to, When You Have To Contextual Styling: UI Components, Nesting, and Implementation Detail Subtleties with Self-Chained Classes Cyclomatic Complexity: Logic in CSS Immutable CSS Can CSS Be Too Modular? More Transparent UI Code with Namespaces When to use @extend; when to use a mixin The Specificity Graph CSS Wizardry Ltd.: Year 1 in review
Maximising hit-area for usability
Harry Roberts · 2011-01-13 · via CSS Wizardry

Written by on CSS Wizardry.

Table of Contents

Independent writing is brought to you via my wonderful Supporters.

  1. A better example
    1. Demo

This post is brought to you by Captain Obvious of The Society of Explaining the Self-Explanatory: increasing the hit area of an object makes it easier to click… Please, don’t let that put you off, there’s more to this article than that; I promise.

So yeah, this is old news. People have, for years, been making the target area for links as big as possible to make them easier for users to click. Hell there’s even a law based on this knowledge, but today I’m only going to share a nifty little trick whereby you don’t just make the hit area bigger, but make it bigger than it appears.

First off, head over to http://suzannahaworth.com/.

I use this technique on the ‘Tweet this’ link at the end of each article. Now before you scroll down and hover that link, notice that we have something that is probably built like this:

<code><element>
  If you liked this article, <link>please Tweet it</link>.
</element></code>

Or so you’d think… What we actually have is this:

<code><link>
  If you liked this article, <element>please Tweet it</element>.
</link></code>

Can you see where this is heading? Good!

The actual code is this:

<code><p id="tweet-this">
  <a href="http://twitter.com/share?text=I&amp;rsquo;m+reading+&amp;lsquo;Crosby Beach&amp;rsquo;&amp;via=suzehaworth&amp;url=http://suzannahaworth.com/2010/12/crosby-beach/">
    If you liked this article, <strong>please Tweet it</strong>.
  </a>
</p></code>

So what we do here is have the whole content of that paragraph as a link–everything is clickable. Then we remove all the styles from that link so that it looks like it’s not a link at all. Anything we set to appear at a{ ... } we effectively remove so that it simply looks like ordinary text. The (abridged) CSS for a{ ... } and the undoing of this is:

<code><span class="code-comment">/* Define generic link styles here */</span>
a{
  font-family:Calibri, Arial, Verdana, sans-serif;
  font-weight:bold;
  color:#347832;
  text-decoration:none;
}
a:hover,a:active,a:focus{
  text-decoration:underline;
}
a:active,a:focus{
  position:relative;
  top:1px;
}

#tweet-this a{
  display:block;
  padding:20px;
  <span class="code-comment">/* Here we undo certain styles applied above */</span>
  font-family:Cambria, Georgia, "Times New Roman", Times, serif;
  font-weight:normal;
  color:#555;
}
#tweet-this a:hover{
  <span class="code-comment">/* Undo the hover state of the link */</span>
  text-decoration:none;
}
#tweet-this strong{
  <span class="code-comment">/* Make this strong look just like the a */</span>
  font-family:Calibri, Arial, Verdana, sans-serif;
  font-weight:bold;
  color:#347832;
}
#tweet-this a:hover strong{
  <span class="code-comment">/* Make this strong look just like the a on hover */</span>
  text-decoration:underline;
}</code>

So here we’re maintaining our specific call to action of ‘please Tweet it’ by styling that as though it’s a link, but in actual fact our link is far bigger. The user sees the specific call-to-action, goes to click it, only to find that it is in fact far larger than it appears, thus easier to click.

Now in this example it would do no harm to just have the whole lot look like a link. We don’t really need to spoof calls-to-actions and hit-areas here but it’s quite a nice feature.


A better example

A better example I unfortunately can’t share just yet as it appears on a site I built that hasn’t gone live. What I can do however is replicate it for you…

The PSD I was handed contained a section where the text was For a detailed quote for your project, please contact us » and its obvious choice of markup was:

<code><p>For a detailed quote for your project, please <a>contact us</a></p></code>

That was until I remembered the technique I’d used on Suze’s site. I could keep the ‘contact us’ call-to-action, but also make it a lot easier for the user to click by using a full-size hit-area.

Demo

I’ve made a (very crude) replica of that for you which you can pick through the source a little more freely.

So there it is, creating larger hit-areas on very specific calls to action.