Days ago I saw a tweet on Twitter Michael Scharnagl
asking people, What’s you favorite CSS snippets which you use again and again?
Rules:
- Has to fit in one tweet
- Has to be vanilla CSS (not Sass, Less…)
- You don’t have to include vendor prefixes
Here’s the original Tweet
Actually most of the snippets I used once or more, and I found some interesting snippets too. I thought about writing a blog post displaying all these snippets in a better way than Twitter tweets
as I don’t like the view of tweets and replies,
So I’ll try to add each useful snippet from the replies of the tweet.
One last thing I’ll try to mention the names of every snippet’s publisher but. I might not be able to mention all the names so you can Back to the tweet and check it.
Let’s start:
@justmarkup
@anandgraves
@M_J_Robbins
Email client isolation;
@machtdesign
Tel-Link - to avoid error
@DasSurma
Reminded to put
alt
on your images:
@justmarkup
@Chrisedmo
A grid system in a tweet:
@radibit
Vertically centering everything:
@tajdidr
You can also use the grid layout 🙂
@ChrisJPatty
I use these material design box shadows constantly. box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); Source
The next tweet will save you a lot of time if you faced this problem before 😄
@noncototient
When you have that on element causing horizontal scroll on the page and you don’t know what it is.
@tzzoo
Target every child except the last one:
@laryro
replied to the previous tweet
Or you could just do this (in case you just want to add a line between elements)
@jim_savage
scaling base value:
@ojrask
@niksy
@snitramordep
Vertical & center align
@michaelpumo Use flexbox for that instead!
@machtdesign
@diegoeis
/_ better css reset of all time _/
@ralfhoffmeister
@holger1411
@jenlampton
@jordanmoore
It still feels like cheating, it’s so easy.
@brunotron3000
Since padding % is related to the element’s width, with this code you can have a responsive square, adjust the % for different aspect ratios (56% for 16:9).
@Danno19008
@_caseyjacobson
@kg_creative
@amiegrrl
@ralfhoffmeister
@bkastl
@mdstaicu
I’m not as cool as the CSS grid kids, I still use this for vertical alignment:
@ShaneHudson
I rely on
for a lot of things
@gerardkcohen
@innovati
Print external URLS:
Demo: https://t.co/QfxHSRbtL7
@RussellSkaggs
@RussellSkaggs
@IschaGast
@keithjgrant
Space out children of a box
@jim_savage
Giving a DIV a custom sized ratio.
@Eramdam
who said centering in CSS was still hard? 😛
@MichaelWhyte
Get list ready for navigation:
@adamtomat
@nice2meatu
(last line only relevant when used inside a flex-container)
@LucP
@MattWilcox
@pxandbeyond
limits the max-width to 75 characters
adds 1 character space where needed
@antikris77
@argyleink
Used like:
Node presents itself when attached to DOM
@GustavoRSSilva
@FPresencia
Magic container responsiveness for all screen sizes:
@selbekk
Great way to sync media queries with your javascript:
@stephenmurdoch
I usually pair the above with a label, and then hide the checkbox.
@wwwulkan
Makes any text that is too long have 3 dots after it. It’s awesome for when you’re tight on horizontal space.
@gups
I know that I did nothing I just copy/paste the tweets content, But I think code here is much better than twitter and I want to use all the new snippets later. If you have any snippets Just comment below and I’ll add it soon with your name.
We can make this post as a great resource for css
snippets
Some useful Links:
- 👨️ My Website/Portfolio
- 🔥 Get your $50 in FREE hosting credit HERE
- 🤑️ No Stripe? How To Get Paid With Payoneer ⇒ $25 + $10 Sign UP Bonus