TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Three CSS features you need to know about

273 pointsby moonlighterabout 12 years ago

18 comments

pjungwirabout 12 years ago
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 未加载
bensummersabout 12 years ago
<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 未加载
iambenabout 12 years ago
-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 未加载
buu700about 12 years ago
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 未加载
silverlightabout 12 years ago
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 未加载
markdownabout 12 years ago
As I recall, calc should be avoided if performance is a consideration in your project.
评论 #5286248 未加载
busticatedabout 12 years ago
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)
geuisabout 12 years ago
To those using calc(), WebKit requires -webkit-calc
评论 #5284164 未加载
trhaynesabout 12 years ago
Examples and browser compatibility stats would have been nice additions to this post.
donutdan4114about 12 years ago
How have I lived without calc() for all this time?....
评论 #5285632 未加载
评论 #5283762 未加载
评论 #5284566 未加载
_ZeD_about 12 years ago
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_thabout 12 years ago
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.
philfreoabout 12 years ago
These are really good tips. I use fancy CSS2 and CSS3 stuff all the time and wasn't familiar with all of these.
leeoniyaabout 12 years ago
wow, calc() is sweet enough to drop a LESS dependency in a lot of cases.
moonlighterabout 12 years ago
attr() seems incredibly useful, and calc() nicely augments static calculations provided by LESS CSS et al. I'm definitely going to use these.
afshinmehabout 12 years ago
Upvote for calc() function, Useful.
importednoobabout 12 years ago
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
rorrrabout 12 years ago
And which major browsers support all of that?
评论 #5284518 未加载