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.

CSS Tips

556 pointsby qubitcoderabout 4 years ago

26 comments

Varaukabout 4 years ago
&gt; Easily center anything, horizontally and vertically, with 3 lines of CSS<p>This can actually be done with 2 lines now!<p><pre><code> .center { display: grid; place-items: center; }</code></pre>
评论 #26946711 未加载
评论 #26946182 未加载
评论 #26946818 未加载
评论 #26953542 未加载
评论 #26953568 未加载
评论 #26953540 未加载
评论 #26952833 未加载
评论 #26946706 未加载
vz8about 4 years ago
I&#x27;d love to see a &quot;Can-I-use&quot; browser extension when looking at articles like this.<p>Occasionally a project requires IE 10&#x2F;11 support (state government work) and it&#x27;s such a shame to get excited about an impossible CSS approach.
评论 #26946946 未加载
评论 #26946898 未加载
评论 #26954048 未加载
评论 #26946939 未加载
评论 #26952793 未加载
评论 #26946709 未加载
elliekellyabout 4 years ago
&gt; * <i>Cursors</i> Did you know that you can use your own image, or even emoji as a cursor?<p>This was the very first bit of CSS I ever learned thanks to my first internet friend, Tom.
评论 #26951006 未加载
spheroidmethodabout 4 years ago
The tooltip example sounds neat, but that approach will run into problems when your tooltips need to appear near the edges of the viewport.<p>Libraries like popper.js (no affiliation) exist to solve this specific problem.
评论 #26947487 未加载
jspashabout 4 years ago
I learned something. But would have been better (easier) if the snippets of code only included the css in question and not fonts&#x2F;backgrounds etc. I had to read each a few times to find the relevant bits.
ArlenBalesabout 4 years ago
Okay, the &quot;:target&quot; psuedo class just blew my mind. Not necessarily for modals (which I don&#x27;t particularly like) but I can think of a lot of other uses. Edit - Apparently it&#x27;s been around for several years. Not sure how I missed this.
评论 #26947524 未加载
评论 #26951507 未加载
评论 #26953001 未加载
emmanueloga_about 4 years ago
HTML tip: provide an ID to headers so you can link to them directly! :-) Also, provide an anchor so users can just copy the link and not have to inspect the html or use an extension to link to your headers.
MR4Dabout 4 years ago
This is a nice list of things that are actually useful and surprisingly straightforward to do.<p>Considering how many people (myself included) consider CSS a veritable minefield, I love seeing examples like this.
runarbergabout 4 years ago
Scrollbar styling is arguably a lot easier using the standard CSS-scrollbars-level-1[1]<p><pre><code> scrollbar-color: rebeccapurple gold; scrollbar-width: thin; </code></pre> As a bonus it works in firefox.<p>1: <a href="https:&#x2F;&#x2F;drafts.csswg.org&#x2F;css-scrollbars-1&#x2F;" rel="nofollow">https:&#x2F;&#x2F;drafts.csswg.org&#x2F;css-scrollbars-1&#x2F;</a>
bradstewartabout 4 years ago
I thought I knew CSS pretty well, but<p><pre><code> position: sticky </code></pre> is a new one for me.
评论 #26947297 未加载
评论 #26946761 未加载
评论 #26946350 未加载
评论 #26954305 未加载
评论 #26946365 未加载
评论 #26946327 未加载
not_knuthabout 4 years ago
Pretty neat. The scroll snapping makes creating a scrollable image carousel super easy.
WORMS_EAT_WORMSabout 4 years ago
Fantastic article. Learned some things. Well done, loved the read.<p>Surprisingly most of these have great browser support.
评论 #26946218 未加载
sandreasabout 4 years ago
I miss the push-button and border-triangle trick;)<p><a href="https:&#x2F;&#x2F;pilabor.com&#x2F;blog&#x2F;tricks-you-might-not-know&#x2F;html-and-css-tricks&#x2F;#3d-button-push-effect-for-links" rel="nofollow">https:&#x2F;&#x2F;pilabor.com&#x2F;blog&#x2F;tricks-you-might-not-know&#x2F;html-and-...</a>
评论 #27012999 未加载
评论 #26946606 未加载
system2about 4 years ago
I stopped adding fancy stuff years ago after realizing browser compatibility has real consequences. :D
评论 #26947083 未加载
TurplePurtleabout 4 years ago
Cool stuff, but wish there was a disclaimer saying many of the things here are Chrome-only. The target audience for this might not consider browser compatibility from the get-go and have to re-think their UI later.
评论 #26946640 未加载
robertoandredabout 4 years ago
Don&#x27;t use their modal trick, it breaks accessibility.
评论 #26952518 未加载
评论 #26948624 未加载
jay_kyburzabout 4 years ago
That custom scrollbar tip doesn&#x27;t work very well in Firefox :)
cosmoticabout 4 years ago
Half these things should be avoided. Don&#x27;t mess with scroll or scroll bars. If a user wants smooth scroll, they will enable it in their browser. Snappy scroll is unpredictable and disorienting.
评论 #26946406 未加载
评论 #26946552 未加载
评论 #26946896 未加载
评论 #26946241 未加载
rchaudabout 4 years ago
Good list, I did not know that text image mask effects were so simple. In fact half of these examples covered things I had no idea about.<p>The custom scrollbars example did not work on Firefox on OSX. all the boxes had identical scrollbars, the OS default.
评论 #26950554 未加载
klausjensenabout 4 years ago
What a great post, I learned a lot!<p>I really liked the ones about truncating text - which also taught me what &quot;ellipsis&quot; means. It is the dots in this example:<p>This text is trun...
lwansbroughabout 4 years ago
One trick that I&#x27;m pretty sure I invented is useful in the case where you may be implementing some sort of Material Design palette: you want to use shades of a colour without manually defining them but are losing saturation if you simply use ie. `rgba(255, 255, 255, 0.2)` -- just add `backdrop-filter: saturate(120%)`. This forces the browser renderer to over-saturate the white by mixing in the background colour. Unfortunately Firefox doesn&#x27;t recognize this CSS property yet but it works fine in WebKit et al.
joemiabout 4 years ago
Interesting, though I would have liked to see the browser support for each of these. Seeing so many -webkit prefixes is a bit concerning.
raspyberrabout 4 years ago
What is codepen.io? Why does this website need to load from a third party to show text...
t0t4labout 4 years ago
Some good tips in there, thanks for sharing.<p>For anyone looking to really learn CSS for layout the resource I recommend is always <a href="https:&#x2F;&#x2F;every-layout.dev" rel="nofollow">https:&#x2F;&#x2F;every-layout.dev</a><p>Heydon Pickering and Andy Bell know what they’re talking about, and they explain the “how and why”
citrus1330about 4 years ago
I learned some new techniques here! Thanks!
darepublicabout 4 years ago
thanks for the typing tip, I once considered using a jquery lib to do the same