Introduction to Defensive CSS
defensivecss.dev
defensivecss.dev
When making styles for dynamic content, CSS should accommodate a decent variety of possible text lengths and image sizes.
This is obviously a good thing.
The improper interpretation is to write CSS so it’s future proof. Don’t do this - you don’t know what future will happen. Solve the problem you have today, cleanly. If someone else comes along and has to edit your CSS and sees all of this extra rules for a problem that doesn’t exist, they’re going to have a hard time knowing what they can and can not change. In general CSS test coverage is especially poor, and so it’s much easier to edit if all CSS is useful.
Maybe this is obvious to me from having built website builders and themes for them, but when making a product that displays unknown, potentially user-generated content, it's to be expected that the content will be different from the boilerplate designs. Working around edge cases like image aspect ratios and words/sentences of varying length are a core part of the UI's development process.
How about catering for (from top of my head): - n elements in group (min vs max - ie top menu will always have at least one element, max element it can have is 10) - element defining properties that are always present and not (if we have Product box that Product will always have title; it might not have description, stock indicator, image etc) - width / height reserved for display of given element (each element reserves this width and this height, ie amount of products in basket is reserved to 20px / 20px irregardless of elements in basket)
I don't know what "they" want, but I do know that back when tables were used, there seemed to be fewer problems. I assume that's because using tables is simpler to do and understand. CSS, of course, is more powerful.
True. As I said, CSS is more powerful. It's too bad that I think responsive design is a terrible thing, though.