





















I spent years teaching CSS layout on this blog. I put everything I know into The Layout Maestro course: 70+ lessons and 150+ interactive examples that teach you how to think CSS layouts, not just memorize syntax.
When we’re very focused on working on a web project, we tend to forget or do some mistakes that can lead to an invalid CSS code. I like to call these “Autopilot mistakes”. The kind of mistakes that make us ask ourselves: “Oops, why did I do that?”, and solving them doesn’t take much time, only if you found them in the first place.
I asked on Twitter about the funniest mistakes that a front-end developer can do, and I got some funny responses.
— Ahmad Shadeed (@shadeed9) August 9, 2020
In this article, I will go through some of the most common and funny CSS mistakes that we do while in autopilot.
Mistaking between font-size and font-weight is common. Here is the mistake that I do too much.
.title {
font-size: bold;
}
I don’t exactly know the reason, but sometimes I tend to forget the percentage for the opacity value.
.title {
opacity: 50;
}
Another common issue is mistyping the opacity property.
.title {
/* It's not easy to spot this */
opaciy: 0.5;
}
Is it light or lighter?
.title {
font-weight: light;
}
This can happen when you think that the property is padding, while in reality, it’s padding-top.
.section {
padding-top: 10px 20px;
}
Sometimes, I type grid-column instead of grid-template-columns.
.section {
grid-columns: 1fr 1fr 1fr;
}
I don’t why, but I found that I’m too lazy to write var(--brand-color) instead.
.title {
color: --brand-color;
}
I always forget that box-shadow should be reset by using none.
.title {
/* Invalid */
box-shadow: 0;
}
Also mentioned by Ahmed Hosna
Credit goes to Ori Livni
.title {
visibility: none;
}
I can’t count the times I did this, and it reminds me of Sublime Text.
Credit goes to bullzito
.title {
widows: 100px;
}
There is a weird feeling of abandoning units from CSS offset properties for a positioned element.s
Credit goes to ciruelo
.elem {
left: 14;
}
If the code editor you’re using doesn’t provide proper highlighting, you will miss this one.
Credit goes to Sven Wolfermann
.elem {
font-size: clac(14px + 1vw);
}
I remember facing such a mistake. Maybe that’s the result of using red to quickly prove something?
Credit goes to TJ Trewin
.elem {
color: #red;
}
.title {
display: absolute;
}
Credit goes to Nitin Suresh
.title {
translate: (-50%, -50%);
}
Credit goes to Håvard Bob
In that regard, I’m excited to let you know that I’m writing an ebook about Debugging CSS.

If you’re interested, head over to debuggingcss.com and subscribe for updates about the book.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。