TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Three CSS features you need to know about

273 点作者 moonlighter大约 12 年前

18 条评论

pjungwir大约 12 年前
Wow, for a "three things you need to know" title, this article was surprisingly informative. Combining attr with :before is a nice trick; I'll be on the lookout for my own reasons to use that. And calc sounds great.
评论 #5284878 未加载
评论 #5284956 未加载
评论 #5285172 未加载
评论 #5284499 未加载
评论 #5288238 未加载
评论 #5286000 未加载
bensummers大约 12 年前
<a href="http://caniuse.com/" rel="nofollow">http://caniuse.com/</a> is a wonderful resource for checking exactly which browsers support new and exciting features, and whether they need a prefix.
评论 #5284557 未加载
iamben大约 12 年前
-moz-box-sizing: border-box; -webkit-box-sizing: border-box;<p>...is a great alternative to the calc example - ie Set your width to 100% and your padding to 100px.<p>Edit: code is a little mangled, just Google it.
评论 #5283723 未加载
评论 #5284020 未加载
buu700大约 12 年前
I've found attr() useful on occasion, but I can't believe that I've carried on for so long assuming the only way to subtract pixels from percentages in my styling was to use JS.<p>As an aside, is Aptiverse in YC? If not, the logo could potentially be a case of mild trademark infringement.
评论 #5284143 未加载
评论 #5283819 未加载
评论 #5284063 未加载
silverlight大约 12 年前
Is calc() performant in modern browsers (IE10, Chrome, Firefox)? I got scared off of it a few years ago when it was first announced because I read that the performance hit was very noticeable...
评论 #5284061 未加载
评论 #5283366 未加载
markdown大约 12 年前
As I recall, calc should be avoided if performance is a consideration in your project.
评论 #5286248 未加载
busticated大约 12 年前
These are nice but it's funny how they fall short:<p>1: you can't combine attr() and calc() - calc(attr(data-count) + 10) &#60;-- nope<p>2: how would you count down from an arbitrary number of child elements? you need to set the total via counter-reset... and, no you can't do content-reset: foo attr(data-count)
geuis大约 12 年前
To those using calc(), WebKit requires -webkit-calc
评论 #5284164 未加载
trhaynes大约 12 年前
Examples and browser compatibility stats would have been nice additions to this post.
donutdan4114大约 12 年前
How have I lived without calc() for all this time?....
评论 #5285632 未加载
评论 #5283762 未加载
评论 #5284566 未加载
_ZeD_大约 12 年前
is there a way for attr() (or similar) to access other css properties? In the example there is<p><pre><code> .child { position: absolute; left: 100px; width: calc(90% - 100px); background-color: #ff8; text-align: center; } </code></pre> whould be gorgeous to write instead<p><pre><code> .child { position: absolute; left: 100px; width: calc(90% - attr(left px)); background-color: #ff8; text-align: center; } </code></pre> the mdn attr page[0] says it can also access properties, but I cannot find a way<p>[0] <a href="https://developer.mozilla.org/en-US/docs/CSS/attr" rel="nofollow">https://developer.mozilla.org/en-US/docs/CSS/attr</a>
ht_th大约 12 年前
I've used attr()to do some localisation, i.e., add "Chapter" or "Kapitel" before an H1 chapter heading depending on the lang attribute on the HTML element. Useful stuff.
philfreo大约 12 年前
These are really good tips. I use fancy CSS2 and CSS3 stuff all the time and wasn't familiar with all of these.
leeoniya大约 12 年前
wow, calc() is sweet enough to drop a LESS dependency in a lot of cases.
moonlighter大约 12 年前
attr() seems incredibly useful, and calc() nicely augments static calculations provided by LESS CSS et al. I'm definitely going to use these.
afshinmeh大约 12 年前
Upvote for calc() function, Useful.
importednoob大约 12 年前
display:none vs visibility:hidden is a need-to-know display: inline-block coupled with font-size: 0px on the parent is huge as well inset box-shadows are pretty cute too
rorrr大约 12 年前
And which major browsers support all of that?
评论 #5284518 未加载