{"id":1309,"date":"2022-02-07T20:45:48","date_gmt":"2022-02-07T20:45:48","guid":{"rendered":"https:\/\/mobileaders.com\/?p=1309"},"modified":"2022-02-07T20:52:39","modified_gmt":"2022-02-07T20:52:39","slug":"minimize-code-duplication","status":"publish","type":"post","link":"https:\/\/mobileaders.com\/?p=1309","title":{"rendered":"Minimize code duplication"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-style-default is-layout-flow wp-block-quote-is-layout-flow\"><p>Keeping code DRY and maintainable is one of the biggest challenges in software development, and that applies to CSS as well. In practice, one big component of maintainable code is minimizing the number of edits necessary to make a change. For example, if to enlarge a button you need to make 10 edits in many different rules, chances are you will miss a few of them, especially if you are not the one who wrote the original code. Even if the edits are obvious, or you eventually find them, you have just wasted<br>time that could be put to better use. Furthermore, this is not just about future changes. Flexible CSS makes it easier to write CSS once, and then create variations with very little code, as there are only a few values you need to override.<\/p><cite><a href=\"https:\/\/www.oreilly.com\/library\/view\/css-secrets\/9781449372736\/\">CSS Secrets<\/a>: by&nbsp;Lea Verou<\/cite><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>padding: 6px 16px;\nborder: 1px solid #446d88;\nbackground: #58a linear-gradient(#77a0bb, #58a);\nborder-radius: 4px;\nbox-shadow: 0 1px 5px gray;\ncolor: white;\ntext-shadow: 0 -1px 1px #335166;\nfont-size: 20px;\nline-height: 30px;<\/code><\/pre>\n\n\n\n<p>To make your code maintainable we will make some changes to the last code, for example, if we want to change our element font-size to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>font-size:40px;<\/code><\/pre>\n\n\n\n<p>what we do previous is wrong we shouldn&#8217;t specify the absolute length, absolute length is easy to work but they come back to bit you every single time you make changes, now if we want to make element parent font-size bigger,we should change every single role in the style sheet, so it&#8217;s better  if we use percentages or ems or rem,..etc <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>font-size:2em<\/code><\/pre>\n\n\n\n<p>now if I change parent font-size our element will instantly become bigger, <strong>so when values depend on each other, try to reflect their relationship in the code <\/strong><\/p>\n\n\n\n<p>Our new code is :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>padding: 0.3em 1em;\nborder: 1px solid #446d88;\nbackground: #58a linear-gradient(#77a0bb, #58a);\nborder-radius:0.2em;\nbox-shadow: 0 0.05em 0.25em gray;\ncolor: white;\ntext-shadow: 0 -0.05em 0.05em #335166;\nfont-size: 2em;\nline-height: 1.5;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Maintainability and Brevity:<\/strong><\/p>\n\n\n\n<p>maintainability and brevity can be mutually exclusive for example if we want to make border to all sides of a specific element expect left side <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>border:10px 10px 10px 0;<\/code><\/pre>\n\n\n\n<p>it&#8217;s only one declaration , but to change the border thickness we would neeed to make three edits, so i thinck if we make edit as two declaration  it would be easy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>border-width:10px;\nborder-left-width:0;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Inheritance<\/strong>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The&nbsp;<code><strong>inherit<\/strong><\/code>&nbsp;CSS keyword is used to have the property take the same specified value as the property of the element\u2019s parent. Specifying a value of&nbsp;<code>inherit<\/code>&nbsp;for any CSS property, that\u2019s applied to an element will cause the element to get its parent\u2019s computed value for that property.<\/p><cite><strong>Codrops Reference<\/strong><\/cite><\/blockquote>\n\n\n\n<p>it always corresponds to the<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/computed_value\"> computed value<\/a> of the parent and it is useful for the background as well.<br>for example, to create speech bubbles  where the pointer  automatically in-inherits the background and border <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.callout { position: relative; }\n\n.callout::before {\ncontent: \"\";\nposition: absolute;\ntop: -.4em; left: 1em;\npadding: .35em;\nbackground: inherit;\nborder: inherit;\nborder-right: 0;\nborder-bottom: 0;\ntransform: rotate(45deg);\n}<\/code><\/pre>\n\n\n\n<p>This is the first article in a <span id=\"6cb4d880-87b1-4270-a34d-c82fe56559be\">series of CSS coding tips so i hope to see you again <br>good luck<\/span><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><br><strong>References:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-vanseo-design wp-block-embed-vanseo-design\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"iVhtWAQFoK\"><a href=\"https:\/\/vanseodesign.com\/css\/dry-principles\/\">DRY CSS: Don&#8217;t Repeat Your CSS<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;DRY CSS: Don&#8217;t Repeat Your CSS&#8221; &#8212; Vanseo Design\" src=\"https:\/\/vanseodesign.com\/css\/dry-principles\/embed\/#?secret=CwF770TSPq#?secret=iVhtWAQFoK\" data-secret=\"iVhtWAQFoK\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/Building_blocks\/Organizing\">https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/Building_blocks\/Organizing<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Keeping code DRY and maintainable is one of the biggest challenges in software development, and that applies to CSS as well. In practice, one big component of maintainable code is minimizing the number of edits necessary to make a change. For example, if to enlarge a button you need to make 10 edits in many [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1315,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[20,1,19],"tags":[27,3,26],"class_list":["post-1309","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-front-end","category-uncategorized","category-web-design","tag-css","tag-development","tag-frontend"],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Minimize code duplication - Mobileaders<\/title>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Minimize code duplication - Mobileaders\" \/>\n<meta property=\"og:description\" content=\"Keeping code DRY and maintainable is one of the biggest challenges in software development, and that applies to CSS as well. In practice, one big component of maintainable code is minimizing the number of edits necessary to make a change. For example, if to enlarge a button you need to make 10 edits in many [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mobileaders.com\/?p=1309\" \/>\n<meta property=\"og:site_name\" content=\"Mobileaders\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/mobileaders\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-07T20:45:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-07T20:52:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"480\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mobileaders\" \/>\n<meta name=\"twitter:site\" content=\"@mobileaders\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mobileaders.com\/?p=1309#article\",\"isPartOf\":{\"@id\":\"https:\/\/mobileaders.com\/?p=1309\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Minimize code duplication\",\"datePublished\":\"2022-02-07T20:45:48+00:00\",\"dateModified\":\"2022-02-07T20:52:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mobileaders.com\/?p=1309\"},\"wordCount\":454,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mobileaders.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/mobileaders.com\/?p=1309#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg\",\"keywords\":[\"css\",\"development\",\"frontend\"],\"articleSection\":{\"0\":\"Front End\",\"2\":\"Web Design\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mobileaders.com\/?p=1309#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mobileaders.com\/?p=1309\",\"url\":\"https:\/\/mobileaders.com\/?p=1309\",\"name\":\"Minimize code duplication - Mobileaders\",\"isPartOf\":{\"@id\":\"https:\/\/mobileaders.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mobileaders.com\/?p=1309#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mobileaders.com\/?p=1309#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg\",\"datePublished\":\"2022-02-07T20:45:48+00:00\",\"dateModified\":\"2022-02-07T20:52:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/mobileaders.com\/?p=1309#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mobileaders.com\/?p=1309\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobileaders.com\/?p=1309#primaryimage\",\"url\":\"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg\",\"contentUrl\":\"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg\",\"width\":640,\"height\":480},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mobileaders.com\/?p=1309#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mobileaders.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Minimize code duplication\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mobileaders.com\/#website\",\"url\":\"https:\/\/mobileaders.com\/\",\"name\":\"Mobileaders\",\"description\":\"Leaders of Mobile Development!\",\"publisher\":{\"@id\":\"https:\/\/mobileaders.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mobileaders.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/mobileaders.com\/#organization\",\"name\":\"mobileaders\",\"url\":\"https:\/\/mobileaders.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobileaders.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/mobileaders.com\/wp-content\/uploads\/2021\/12\/Logo-White-Background.png\",\"contentUrl\":\"https:\/\/mobileaders.com\/wp-content\/uploads\/2021\/12\/Logo-White-Background.png\",\"width\":1280,\"height\":720,\"caption\":\"mobileaders\"},\"image\":{\"@id\":\"https:\/\/mobileaders.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/mobileaders\",\"https:\/\/x.com\/mobileaders\",\"https:\/\/www.instagram.com\/mobileaders\",\"https:\/\/www.linkedin.com\/company\/mobileaders\"]},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Minimize code duplication - Mobileaders","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"Minimize code duplication - Mobileaders","og_description":"Keeping code DRY and maintainable is one of the biggest challenges in software development, and that applies to CSS as well. In practice, one big component of maintainable code is minimizing the number of edits necessary to make a change. For example, if to enlarge a button you need to make 10 edits in many [&hellip;]","og_url":"https:\/\/mobileaders.com\/?p=1309","og_site_name":"Mobileaders","article_publisher":"https:\/\/www.facebook.com\/mobileaders","article_published_time":"2022-02-07T20:45:48+00:00","article_modified_time":"2022-02-07T20:52:39+00:00","og_image":[{"width":640,"height":480,"url":"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_creator":"@mobileaders","twitter_site":"@mobileaders","twitter_misc":{"Written by":"","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mobileaders.com\/?p=1309#article","isPartOf":{"@id":"https:\/\/mobileaders.com\/?p=1309"},"author":{"name":"","@id":""},"headline":"Minimize code duplication","datePublished":"2022-02-07T20:45:48+00:00","dateModified":"2022-02-07T20:52:39+00:00","mainEntityOfPage":{"@id":"https:\/\/mobileaders.com\/?p=1309"},"wordCount":454,"commentCount":0,"publisher":{"@id":"https:\/\/mobileaders.com\/#organization"},"image":{"@id":"https:\/\/mobileaders.com\/?p=1309#primaryimage"},"thumbnailUrl":"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg","keywords":["css","development","frontend"],"articleSection":{"0":"Front End","2":"Web Design"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mobileaders.com\/?p=1309#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mobileaders.com\/?p=1309","url":"https:\/\/mobileaders.com\/?p=1309","name":"Minimize code duplication - Mobileaders","isPartOf":{"@id":"https:\/\/mobileaders.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mobileaders.com\/?p=1309#primaryimage"},"image":{"@id":"https:\/\/mobileaders.com\/?p=1309#primaryimage"},"thumbnailUrl":"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg","datePublished":"2022-02-07T20:45:48+00:00","dateModified":"2022-02-07T20:52:39+00:00","breadcrumb":{"@id":"https:\/\/mobileaders.com\/?p=1309#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mobileaders.com\/?p=1309"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobileaders.com\/?p=1309#primaryimage","url":"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg","contentUrl":"https:\/\/mobileaders.com\/wp-content\/uploads\/2022\/02\/med_1584113012_image.jpeg","width":640,"height":480},{"@type":"BreadcrumbList","@id":"https:\/\/mobileaders.com\/?p=1309#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mobileaders.com\/"},{"@type":"ListItem","position":2,"name":"Minimize code duplication"}]},{"@type":"WebSite","@id":"https:\/\/mobileaders.com\/#website","url":"https:\/\/mobileaders.com\/","name":"Mobileaders","description":"Leaders of Mobile Development!","publisher":{"@id":"https:\/\/mobileaders.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mobileaders.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/mobileaders.com\/#organization","name":"mobileaders","url":"https:\/\/mobileaders.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobileaders.com\/#\/schema\/logo\/image\/","url":"https:\/\/mobileaders.com\/wp-content\/uploads\/2021\/12\/Logo-White-Background.png","contentUrl":"https:\/\/mobileaders.com\/wp-content\/uploads\/2021\/12\/Logo-White-Background.png","width":1280,"height":720,"caption":"mobileaders"},"image":{"@id":"https:\/\/mobileaders.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/mobileaders","https:\/\/x.com\/mobileaders","https:\/\/www.instagram.com\/mobileaders","https:\/\/www.linkedin.com\/company\/mobileaders"]},{"@type":"Person","@id":""}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/mobileaders.com\/index.php?rest_route=\/wp\/v2\/posts\/1309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mobileaders.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mobileaders.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mobileaders.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mobileaders.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1309"}],"version-history":[{"count":5,"href":"https:\/\/mobileaders.com\/index.php?rest_route=\/wp\/v2\/posts\/1309\/revisions"}],"predecessor-version":[{"id":1314,"href":"https:\/\/mobileaders.com\/index.php?rest_route=\/wp\/v2\/posts\/1309\/revisions\/1314"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mobileaders.com\/index.php?rest_route=\/wp\/v2\/media\/1315"}],"wp:attachment":[{"href":"https:\/\/mobileaders.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mobileaders.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mobileaders.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}