CodePen<\/a>.<\/p>\nThis is a particularly graceful fallback, because it means that no matter what<\/em>, the user will be able to access all of the content. Plus, the scrollbar will only appear if it’s needed, which means it’s not a bad idea to add this property in key places, even if you don’t expect it to come into play.<\/p>\nWhy does this conundrum resonate so universally with people who have used CSS?<\/h3>\n
CSS is hard because its properties interact, often in unexpected ways. Because when you set one of them, you’re never just setting that one thing. That one thing combines and bounces off of and contradicts with a dozen other things, including default things that you never actually set yourself.<\/p>\n
One rule of thumb for mitigating this is, never be more explicit than you need to be<\/strong>. Web pages are responsive by default. Writing good CSS means leveraging that fact instead of overriding it. Use percentages or viewport units instead of a media query if possible. Use min-width<\/code> instead of width<\/code> where you can. Think in terms of rules, in terms of what you really mean to say<\/em>, instead of just adding properties until things look right. Try to get a feel for how the browser resolves layout and sizing, and make your changes and additions on top of that judiciously. Work with CSS, instead of against it.<\/p>\nAnother rule of thumb is to let either width or height be determined by content<\/strong>. In this case, that wasn’t enough, but in most cases, it will be. Give things an avenue for expansion. When you’re setting rules for how your elements get sized, especially if those elements will contain text content, think through the edge cases. “What if this content was pared down to a single character? What if this content expanded to be three paragraphs? It might not look great, but would my layout be totally broken?”<\/p>\nCSS is weird. It’s unlike any other code, and that makes a lot of programmers uncomfortable. But used wisely it can, in fact, be awesome.<\/p>\n","protected":false},"excerpt":{"rendered":"
I bought this mug recently for use at work. Being a professional web developer, I decided it would establish me as the office’s king of irony. The joke on it isn’t unique, of course. I’ve seen it everywhere from t-shirts to conference presentations.<\/p>\n","protected":false},"author":243416,"featured_media":255927,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[4],"tags":[],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2017\/06\/css-is-awesome-scaled.jpg?fit=2560%2C2013&ssl=1","jetpack-related-posts":[{"id":301447,"url":"https:\/\/css-tricks.com\/how-many-css-properties-are-there\/","url_meta":{"origin":255923,"position":0},"title":"How many CSS properties are there?","date":"January 14, 2020","format":false,"excerpt":"Tomasz \u0141akomy posted a joke tweet about naming all the CSS attributes and Tejas Kumar replied with a joke answer, going as far as making an npm module. You can even run a terminal command to see them: npx get-all-css-properties You'll get 259 of them. The source code uses the\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/08\/css-sparkle-1.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":340919,"url":"https:\/\/css-tricks.com\/css-hell\/","url_meta":{"origin":255923,"position":1},"title":"CSS Hell","date":"May 21, 2021","format":false,"excerpt":"Collection of common CSS mistakes, and how to fix them From Stef\u00e1nia P\u00e9ter. Clever idea for a site! Some of them are little mind-twisters that could bite you, and some of them are honing in on best practices that may affect accessibility. Why \"CSS Hell\"? It's a\u00a0joke\u00a0idea I stole from\u00a0HTMHell.\u2026","rel":"","context":"In "Link"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/05\/Screen-Shot-2021-05-19-at-10.18.58-AM.png?fit=1084%2C452&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":342358,"url":"https:\/\/css-tricks.com\/inline-styles-as-classes-lol\/","url_meta":{"origin":255923,"position":2},"title":"Inline Styles as Classes (lol)","date":"June 16, 2021","format":false,"excerpt":"If you're abhorred by using inline styles, just move that style to the class attribute! And then make sure you have CSS in place that, ya know, does what it says on the box. https:\/\/twitter.com\/samthor\/status\/1402825668061130755 OK lemme dig in and totally ruin the joke. First off, it's a joke, so\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/06\/E3fWebBVUAQOoaZ.png?fit=620%2C480&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":314419,"url":"https:\/\/css-tricks.com\/the-mad-magazine-fold-in-effect-in-css\/","url_meta":{"origin":255923,"position":3},"title":"The Mad Magazine Fold-In Effect in CSS","date":"June 25, 2020","format":false,"excerpt":"This was always my favorite thing in Mad magazine. One page (the inside of the back cover, I think) was covered in a zany illustration. You folded that page in thirds, covering up the middle-third of that image, and a new image would form because the illustration was designed to\u2026","rel":"","context":"In "Link"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2020\/06\/mad-magazine-fold-in.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":340599,"url":"https:\/\/css-tricks.com\/json-in-css\/","url_meta":{"origin":255923,"position":4},"title":"JSON in CSS","date":"May 20, 2021","format":false,"excerpt":"Jonathan Neal tweeted a heck of a little CSS trick the other day, putting JSON inside CSS and plucking it out with JavaScript. Valid values for custom properties are quite liberal! So this looks for a CSS rule (e.g. a whole block, like #x { y: z; } where the\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/05\/css-json.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":317266,"url":"https:\/\/css-tricks.com\/position-vertical-scrollbars-on-opposite-side-with-css\/","url_meta":{"origin":255923,"position":5},"title":"Position Vertical Scrollbars on Opposite Side with CSS","date":"July 22, 2020","format":false,"excerpt":"Fair warning: I can't say I recommend this in general because it breaks a very strong expectation of where scrollbars are, which are useful for a lots of folks, not to mention, a core accessibility feature for many. But it is a fascinating CSS trick and the web is a\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2020\/04\/scrollbar-progress.png?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"featured_media_src_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2017\/06\/css-is-awesome-scaled.jpg?fit=1024%2C805&ssl=1","_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/255923"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/243416"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=255923"}],"version-history":[{"count":7,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/255923\/revisions"}],"predecessor-version":[{"id":256261,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/255923\/revisions\/256261"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media\/255927"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=255923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=255923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=255923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}