{"id":3376,"date":"2022-04-28T19:00:00","date_gmt":"2022-04-28T19:00:00","guid":{"rendered":"https:\/\/cssdeck.com\/blog\/?p=3376"},"modified":"2022-04-27T13:11:18","modified_gmt":"2022-04-27T13:11:18","slug":"css-min-max-guide-for-efficiency","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/css-min-max-guide-for-efficiency\/","title":{"rendered":"Css Min Max Guide for Efficiency"},"content":{"rendered":"\n<p>Functions like CSS, min, and max can revolutionize web layout features. However, they also can make CSS hard to reason about if used to their full potential.<\/p>\n\n\n\n<p><strong>See also: <a href=\"https:\/\/cssdeck.com\/blog\/showhide-content-css-javascript\/\">Show\/Hide Content with CSS and JavaScript<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The functions<\/h2>\n\n\n\n<ul><li>min(): lets you set the most negative value from a list of comma-separated expressions as the value of a CSS property value<\/li><\/ul>\n\n\n\n<ul><li>max(): lets you set the most positive value from a list of comma-separated expressions as the value of a CSS property value<\/li><\/ul>\n\n\n\n<p>Another interesting note is that you could do math inside the function without using calc. So, in place of min(calc(5vw + 5px), 50px); you could just do min(5vw + 5px, 50px). Of course, you may also have achieved your calculation in a variable and used that variable.<\/p>\n\n\n\n<p>One factor that is probably confusing is the naming CSS min() returns the minimum value from its list of values, and max() returns its maximum value, as you may count on. However, what might show up if I were to do the subsequent (a ridiculous usage for the motive of the instance):<\/p>\n\n\n\n<p>width: min(1px,200px,300px);<\/p>\n\n\n\n<p>Of course, 1px returns, which means that the output of the CSS min function sets the maximum value of that width to be 1px.<\/p>\n\n\n\n<p>An occasional point of bewilderment when the usage of min()\/max() in which you use most () to impose a minimum value on something.<\/p>\n\n\n\n<p>For instance, properties like min-width efficiently use max()) and min() to impose a maximum on something; it&#8217;s easy to accidentally attain for the other feature and try to use min() to add a minimal size.<\/p>\n\n\n\n<p><strong>See also: <a href=\"https:\/\/cssdeck.com\/blog\/4-ways-css-can-improve-your-seo\/\">4 Ways CSS Can Improve Your SEO<\/a><\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">CSS Breakpoints<\/h1>\n\n\n\n<p>You could add CSS breakpoints using min-width, max-width, or both aggregate.<\/p>\n\n\n\n<p>By default, we might be setting the patterns for small screen devices and later upload &amp; modify them for larger monitors.<\/p>\n\n\n\n<p>Likewise, we should use max-width breakpoints to design our layout for big-screen devices. We&#8217;d set the patterns for big-screen gadgets and later upload &amp; adjust for smaller monitors by default.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Min-content keyword<\/h1>\n\n\n\n<p>The W3C specs state the min-content material is the most petite length a field can take without overflowing its content material.<\/p>\n\n\n\n<p>For horizontal content material, the min-content material uses the period of the broadest little bit of content material in the element box and routinely units that length price because of the width.<\/p>\n\n\n\n<p>If we revisit the container instance above, we can apply the min-content to the container element like so:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/eSAjxuIvICBH8sWmFcPCiNKK6BP66Ftc8Czom3YfGb8hwkNIVTkXq5ftedTNbVBfkr568kM2n5mRq1gKIUPd_aOvmYlQUVLju3eUHoMgYc0dSX0GKbnSQxsgs871P-sfida6ULXO\" alt=\"\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Max-content keyword<\/h1>\n\n\n\n<p>The <a href=\"https:\/\/www.w3.org\/\"><strong>W3C<\/strong><\/a> specs state that max-content represents a box&#8217;s best size with an infinite available area on a given axis.<\/p>\n\n\n\n<p>Otherwise, max-content material represents the scale a box desires to include all of its content without being wrapped or overflowing the container.<\/p>\n\n\n\n<p>With this, let&#8217;s observe a max-content material to a detailed size:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/NBoYjZAT7xeGU2YfmXupinS1Meyd4pJwpDRGd1nUAGNFeE1YQpFB2hhE0uLB2UZoVxZI5sQcX5VQpMyge7SrPIBMKbx6Mt8oDGZcAKHVpzUudBmWr4xesQwY13ELmwpHToEwvyav\" alt=\"\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">The HSL function<\/h1>\n\n\n\n<p>The abbreviation of HSL is Hue, Saturation, and Lightness and is a character brought in CSS 3. You could refer to this post for a refresher on HSL.<\/p>\n\n\n\n<p>The following example will no longer appear especially useful at first, but test how you can use min and max within the HSL characteristic:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/B-7LFeRfBquLuridgtzEBJwxC_FJqAM7FkVSPnptB_WSiZI4UFWK_WFRJHvixp1cZ800oHuxdrVPsZUYZbKhOIo-IpKkCARmlKeNxt0tfeFJ1Kh9T4UsY8KxF4W6fe9Gl-k0_Lv2\" alt=\"\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Features that may use min(), max()<\/h1>\n\n\n\n<p>Here is a list of capabilities wherein you can use the maths capabilities, even though you might not commonly anticipate to (functions in which you may expect to use them, like calc(), have been left out).<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/Cu8HBO1ybMY4I-_7Sd0rJkF_9kf2cB7t2HUD45Oy8HXReBaCv2rl6txpOFn1OZ3tNe0OPvj0e8ee-_n3BVL9xBENbAX1LtYcj2-JlebtUBYKzE00zy_BnfRibNp-45uVwGNzzvRf\" alt=\"\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Functions working in unexpected ways<\/h1>\n\n\n\n<p>It&#8217;s apparent how you will use these capabilities in functions like width or calc() (or, if no longer at once noticeable, a way to use them, as a minimum). But numerous other approaches may be used that might not be apparent with ease.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/YkiuCUMeE79FgCHkp1GzVwVfTDRQA6VAgkrgihyculWQBdgW-ktKqlFzpK33qHBu2TetlyyF9eE_lytgjBXeKsa0ugKPNN4W9RSYIUiBmP3uP7peXQYbJdNMLfKeYsh1cDgdBdez\" alt=\"\" \/><\/figure>\n\n\n\n<p>The lesson to take from this section is that on account that these functions work on units, you can take as input any feature that returns a \u2014 value like calc() \u2014 (or use them in any characteristic).<\/p>\n\n\n\n<p><strong>See also: <a href=\"https:\/\/cssdeck.com\/blog\/new-to-css\/\">New to CSS? New to CSSnewbie? Start Here!<\/a><\/strong><\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Functions like CSS, min, and max can revolutionize web layout features. However, they also can make CSS hard to reason about if used to their full potential.<\/p>\n<p>See also: Show\/Hide Content with CSS and JavaScript<\/p>\n<p>The functions<\/p>\n<p>min(): lets you set the most [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/css-min-max-guide-for-efficiency\/\" title=\"Click to read 'Css Min Max Guide for Efficiency'\">Read Article<\/a><\/p>\n","protected":false},"author":21,"featured_media":3377,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4,168,172],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3376"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3376"}],"version-history":[{"count":2,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3376\/revisions"}],"predecessor-version":[{"id":3379,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3376\/revisions\/3379"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/3377"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}