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

推荐订阅源

T
Tenable Blog
博客园_首页
Vercel News
Vercel News
WordPress大学
WordPress大学
美团技术团队
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Y
Y Combinator Blog
博客园 - 【当耐特】
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
腾讯CDC
M
MIT News - Artificial intelligence
爱范儿
爱范儿
Recent Announcements
Recent Announcements
雷峰网
雷峰网
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
Jina AI
Jina AI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
P
Privacy & Cybersecurity Law Blog
Recorded Future
Recorded Future
Help Net Security
Help Net Security
N
News and Events Feed by Topic
博客园 - Franky
P
Proofpoint News Feed
L
LINUX DO - 热门话题
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
D
Docker
Google DeepMind News
Google DeepMind News
有赞技术团队
有赞技术团队
IT之家
IT之家
Security Latest
Security Latest
L
LangChain Blog
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
J
Java Code Geeks

David Baron's Weblog

Software engineering, responsibility, and ownership Software engineering, responsibility, and ownership David Baron's weblog: Security and Inequality Running animations on the compositor thread David Baron's weblog: Tying ecosystems through browsers David Baron's weblog: Payments on the Web Thoughts on migrating to a secure Web David Baron's weblog: The need for government David Baron's weblog: Priority of constituencies How browser developers should seek feedback from Web developers A possible approach to shorter release cycles David Baron's weblog: Fifteen years Why debug builds (and assertions) are important Ten years of the Mozilla Foundation Open licensing at the W3C Why adding compositing and blending to CSS is harder than it looks How you can help with removing -moz- prefixes Moving bug history out of the primary display of a bug report Beware of locale-specific behavior in the C library Eating dogfood and shipping software Specification style and the future of the Web The bug system I wish I had CSS border-image changes and unprefixing Improving font size readability on Firefox for Android David Baron's weblog: CSS Animations, part 2 Hue-preserving color inversion with SVG filters Changes to handling of @-moz-keyframes David Baron's weblog: window.matchMedia() David Baron's weblog: CSS Animations What does a blur radius mean? Crash analysis in the future David Baron's weblog: calc() David Baron's weblog: colorDepth David Baron's weblog: Hidden complexity in specifications The most important field in a bug report: the summary WOFF font format submitted to W3C David Baron's weblog: :-moz-any() selector grouping setTimeout with a shorter delay Faster repainting in SVG foreignObject David Baron's weblog: Distributed Extensibility David Baron's weblog: Broadening crash analysis Correlating crashes with binary extensions or plugins David Baron's weblog: ex-HTML Downloadable font formats for the Web Web Accessibility as a Political Movement David Baron's weblog: CSS priorities David Baron's weblog: Bug priorities David Baron's weblog: Semi-vacation Some new CSS features in Firefox 3 David Baron's weblog: New selectors David Baron's weblog: The age of bugs Seeking a good Linux distribution David Baron's weblog: Teaching to the test David Baron's weblog: March 2008 David Baron's weblog: February 2008 David Baron's weblog: January 2008 David Baron's weblog: October 2007 David Baron's weblog: September 2007 David Baron's weblog: August 2007 David Baron's weblog: June 2007 David Baron's weblog: April 2007 David Baron's weblog: January 2007 David Baron's weblog: September 2006 David Baron's weblog: August 2006 David Baron's weblog: July 2006 David Baron's weblog: May 2006 David Baron's weblog: February 2006 David Baron's weblog: January 2006 David Baron's weblog: December 2005 David Baron's weblog: October 2005 David Baron's weblog: September 2005 David Baron's weblog: June 2005 David Baron's weblog: May 2005 David Baron's weblog: April 2005 David Baron's weblog: March 2005 David Baron's weblog: February 2005 David Baron's weblog: October 2004 David Baron's weblog: September 2004 David Baron's weblog: August 2004 David Baron's weblog: June 2004 David Baron's weblog: May 2004 David Baron's weblog: April 2004 David Baron's weblog: March 2004 David Baron's weblog: February 2004 David Baron's weblog: January 2004 David Baron's weblog: November 2003 David Baron's weblog: October 2003 David Baron's weblog: September 2003 David Baron's weblog: August 2003 David Baron's weblog: July 2003 David Baron's weblog: June 2003 David Baron's weblog: May 2003 David Baron's weblog: April 2003 David Baron's weblog: March 2003 David Baron's weblog: February 2003 David Baron's weblog: January 2003 David Baron's weblog: December 2002 David Baron's weblog: November 2002 David Baron's weblog: September 2002
David Baron's weblog: March 2007
David Baron · 2007-03-30 · via David Baron's Weblog

Why clearance sometimes needs to be negative (18:04 -0700)

At the CSS working group meeting in Oslo in August 2003, we came up with a concept called clearance to describe the offset used to change the position of a non-floating element that is moved by the clear CSS property. (Previously, the clear property was defined as increasing the margin.)

At our meeting earlier this week in Mountain View, we discussed a testcase where the current rules cause very strange behavior. The simplest form of this testcase is the following (view):

<div>A</div>
<div>
  <div style="float:left;height:10px;width:10px;background:blue"></div>
  <div style="clear:left; margin-top: 50px">hello</div>
</div>

In an implementation conformant to the current CSS2.1 spec, the 50px top margin of the second inner div disappears, which doesn't seem to be desirable behavior. We're still discussing how to fix this.

But one thing that came up during the discussion is why clearance ever needs to be negative (as it is in this case). A simple example of why clearance needs to be negative is the following testcase:

<p style="height: 20px; margin-bottom: 20px;">
  <img style="float: left">
</p>
<p style="margin-top: 20px; clear: left">Hello</p>

In this testcase, if the image is 40px tall (view), there is no clearance needed, so the paragraphs are separated by 20px (the collapsed margin). However, if the image is 41px tall (view), the second paragraph needs to clear the image, so we have clearance. Since this clearance separates the two margins, they suddenly don't collapse. So the separation between the two blocks ends up, in the current spec, as 20px margin + -19px clearance + 20px margin == 21px. If we didn't allow negative clearance it would suddenly jump to 40px, which is bad.

Now, you might wonder why we put the clearance before the margin rather than putting it between the margin and the border (which might make sense, since we're clearing the border edge). We can explain that with this testcase:

<!-- maybe something above to clear -->
<div style="clear: left; background: yellow">
  <h2 style="margin-top: 1em">Heading</h2>
</div>

If we had put the clearance between the margin and the padding, then if there were no float to clear (view), the h2's margin would collapse with the div's and end up outside the div. But if there were a float to clear past (view), putting the clearance between the margin and border would stop margin collapsing between the h2's top margin and the div's top margin, which would mean that the h2's top margin would suddenly switch to being inside the div.

(For what it's worth, I was never all that happy with the concept of clearance in the first place. It doesn't even fix all the cases where a collapsed margin appears partly on one side of a block's border edge and partly on the other -- although it does reduce such cases to being only for empty blocks. But we then have to add some complicated workarounds to the spec to ensure that empty boxes don't end up outside their parent by providing special rules for their position at the beginning of a block, but we still allow them to be outside their parent (even without negative margins) when they're at the end of a block.)