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

推荐订阅源

U
Unit 42
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News | PayPal Newsroom
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
S
Security @ Cisco Blogs
宝玉的分享
宝玉的分享
Hacker News: Ask HN
Hacker News: Ask HN
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Latest news
Latest news
NISL@THU
NISL@THU
S
Security Affairs
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 聂微东
AI
AI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
小众软件
小众软件
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
AWS News Blog
AWS News Blog
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
I
InfoQ
Schneier on Security
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
IT之家
IT之家
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
腾讯CDC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
H
Heimdal Security Blog
S
SegmentFault 最新的问题

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
Mobile business card
Harry Roberts · 2011-02-23 · via CSS Wizardry

Written by on CSS Wizardry.

Table of Contents

Independent writing is brought to you via my wonderful Supporters.

  1. The code
  2. Issues

Business card style sites are nothing new. Tim Van Damme popularised them a while ago and they’re a handy tool for relaying the most basic and important information about yourself in a very short space of time. I made my own business card type site recently (and tweeted about its self-indulgence) and put some nifty CSS to work–a digital business card whose content changes when you rotate your mobile.

Here it is. Visit this on a desktop browser and in a smartphone (and then try rotating the device).

I was inspired after I saw Engage Interactive’s iPhone site in Paul Annett’s .net magazine article whilst on the train. I only had my iPhone with me which meant that, although in the ideal viewing medium, I wasn’t able to pick apart any source. As my mind so frequently does, I started coding up a ‘my version’ in my head.

After building mine I went and found that Engage’s iPhone site uses JavaScript and works solely on an iPhone (I imagine some for of browser sniffing is used to detect it). This gives them increased functionality as they have horizontal-left and horizontal-right; I only have horizontal but I wanted a device independent site that would work using only CSS.

Read on for the how-to…


The code

What we have here is a page with personal and contact information. We have three possible states: desktop, mobile-portrait and mobile-landscape.

The stacked paper effect is achieved by replicating the appearance of the page <div> in both a :before and :after pseudo-element, giving these a negative z-index and then rotating them. This effect is achieved with no extra markup or images.

<code><span class="code-comment"><!-- Markup --></span>
<div id="page">

  <div id="about">
    
    [content]
  
  </div>
  
  <div id="contact">
    
    [content]
    
  </div>

</div>

<span class="code-comment">/* CSS */</span>
#page{
  position:relative;
  margin:0 auto;
  padding:20px 20px 0 20px;
  border:10px solid #f0f0f0;
  background:#fff;
  width:400px;

  -moz-box-shadow:0 0 10px rgba(0,0,0,0.25);
  -webkit-box-shadow:0 0 10px rgba(0,0,0,0.25);
  -o-box-shadow:0 0 10px rgba(0,0,0,0.25);
  box-shadow:0 0 10px rgba(0,0,0,0.25);
}
#page:before,
#page:after{
  content:" ";
  display:block;
  border:10px solid #f0f0f0;
  background:#fff;
  z-index:-1;
  position:absolute;
  top:-10px;
  right:-10px;
  bottom:-10px;
  left:-10px;
  
  -moz-box-shadow:0 0 10px rgba(0,0,0,0.25);
  -webkit-box-shadow:0 0 10px rgba(0,0,0,0.25);
  -o-box-shadow:0 0 10px rgba(0,0,0,0.25);
  box-shadow:0 0 10px rgba(0,0,0,0.25);
  -moz-transform:rotate(1deg);
  -webkit-transform:rotate(1deg);
  -o-transform:rotate(1deg);
  transform:rotate(1deg);
}
#page:after{
  z-index:-2;
  -moz-transform:rotate(-1.5deg);
  -webkit-transform:rotate(-1.5deg);
  -o-transform:rotate(-1.5deg);
  transform:rotate(-1.5deg);
}</code>

Each type of content is wrapped in its own <div>. This may, at first, seem extraneous but these are the hooks used to toggle the content displayed on mobile devices in different orientations. If your browser is portrait then hide the contact <div>, if it is landscape them hide the about <div>.

I hide each <div> by absolutely positioning it way off to the left of the screen. This offers more accessibility than a simple display:none;:

<code>@media (max-width: 480px) and (orientation: portrait){

#contact{
  position:absolute;
  left:-9999px;
}

}
@media (max-width: 480px) and (orientation: landscape){

#about{
  position:absolute;
  left:-9999px;
}

}</code>

Further, when the page loads on a mobile device an overlay animates in and out with some Webkit animations, telling the user to ‘Try rotating your phone…’

<code><span class="code-comment"><!-- Markup --></span>
<div id="mask"></div>

<p id="instructions">Try rotating your phone…</p>


<span class="code-comment">/* CSS */</span>
<span class="code-comment">/*------------------------------------*\
  INSTRUCTIONS
\*------------------------------------*/</span>
#mask,
#instructions{
  display:block;
  -webkit-animation-duration:3s;
  -webkit-animation-iteration-count:1;
  -webkit-animation-timing-function:linear;
}
#mask{
  position:absolute;
  left:-9999px;
  background:rgba(0,0,0,0.75);
  z-index:2;
  -webkit-animation-name:mask;
}
@-webkit-keyframes mask{
0%{
  opacity:0;
}
10%{
  opacity:1;
  top:0;
  right:0;
  bottom:0;
}
90%{
  opacity:1;
  top:0;
  right:0;
  bottom:0;
}
99%{
  opacity:0;
  top:0;
  right:0;
  bottom:0;
}
100%{
  opacity:0;
}
}
#instructions{
  font-family:Calibri, sans-serif; <span class="code-comment">/* Using a non-Typekit face to try and alleviate the delay in text-display */</span>
  width:200px;
  position:absolute;
  top:-9999px;
  left:50%;
  background:rgba(0,0,0,0.75);
  z-index:3;
  padding:10px;
  background:#fef8c4;
  border:1px solid #d8d566;
  margin:-12px 0 0 -100px;
  font-weight:bold;
  text-align:center;
  
  -moz-box-shadow:0 0 10px rgba(0,0,0,0.75),0 1px #fff inset;
  -webkit-box-shadow:0 0 10px rgba(0,0,0,0.75),0 1px #fff inset;
  -o-box-shadow:0 0 10px rgba(0,0,0,0.75),0 1px #fff inset;
  box-shadow:0 0 10px rgba(0,0,0,0.75),0 1px #fff inset;
  -webkit-animation-name:message;
}
@-webkit-keyframes message{
0%{
  opacity:0;
}
10%{
  opacity:1;
  top:50%;
  left:50%;
}
90%{
  opacity:1;
  top:50%;
  left:50%;
}
99%{
  opacity:0;
  top:50%;
  left:50%;
}
100%{
  opacity:0;
}
}

}
</code>

Another thing to note; the image in the page is used as an inline image, the favicon and the iPhone homescreen icon. The same image has been reused three times, this isn’t anything amazing but it means only one request over a mobile connection.

Issues

Suze bought me Typekit recently which I thought I’d try out, however there is a little bug on mobile whereby Typekit prevents any text from displaying for a moment. The length of this ‘moment’ depends on the speed of your connection.

Furthermore, the overlay mentioned previously is displayed with CSS based on resolution. Ideally you’d use a more robust method of writing this to the view than saying ‘if the screen is really this small then use CSS to display the markup that is there anyway regardless of the device’. Resolution dependence isn’t explicit enough because a) no matter what device you are on, the ‘rotate you phone’ text is always present in the markup and b) a 27” iMac will display the text to the user is they resize their browser down far enough; a user can actually see the phone related text on a desktop if they resize enough.

However, this was just a proof-of-concept idea just to see if I could do it–I’m pretty pleased with the results.