Menu

You Write Backend Code and Someone Has Asked You to Fix the CSS
📰

You Write Backend Code and Someone Has Asked You to Fix the CSS

DEV Community: css·Asael Shinder·7 days ago
#IR79VxM2
#devtocss#devto#dev#learn#element
Reading 0:00
15s threshold

The ticket looks small. A button is sitting a few pixels too low, and the frontend developer is on holiday. You open the stylesheet, change a number, refresh, and something else moves instead. An hour later you have added three rules, one of them with !important on the end, and the button is still wrong.

Most backend developers have a version of this story. CSS feels unpredictable when you treat it as a list of settings. It becomes far more sensible once you learn the few ideas underneath it.

Start with the box model. Every element is a box made of content, then padding, then a border, then margin outside that. By default, the width you set applies only to the content, so padding and border are added on top. Many projects set box-sizing to border-box so that the width includes them. Check which one your project uses before you do any arithmetic.

Learn the cascade, because it explains most of the surprises.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.