{"id":3182,"date":"2022-03-17T12:17:34","date_gmt":"2022-03-17T12:17:34","guid":{"rendered":"https:\/\/cssdeck.com\/blog\/?p=3182"},"modified":"2022-03-28T14:08:52","modified_gmt":"2022-03-28T14:08:52","slug":"css-setting-max-media-to-fit-a-phone","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/css-setting-max-media-to-fit-a-phone\/","title":{"rendered":"CSS Setting Max Media to Fit a Phone"},"content":{"rendered":"\n<p>CSS or Cascading Style Sheet is a language we use to design an <a href=\"https:\/\/en.wikipedia.org\/wiki\/HTML\"><strong>HTML <\/strong><\/a>document. With CSS, you can add unique styles and develop user interfaces without spending much of your time.&nbsp;<\/p>\n\n\n\n<p>In the recent CSS (CSS3) version, a new technique called Media queries was introduced. Generally, it is used for changing and applying various styles for different media types or devices. However, it has several other features to set the maximum or minimum width of the viewport or your device.<\/p>\n\n\n\n<p>This article will try to explain all the queries related to CSS media, CSS media max and min features, and much more. So, keep reading it till the end.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is a Media Query in CSS?<\/strong><\/h2>\n\n\n\n<p>Have you ever noticed changes when you open a website on your desktop and a smartphone? You see a different design of the same website on two other devices, and it is because of the media queries.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"358\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/03\/Screenshot-608.png\" alt=\"\" class=\"wp-image-3184\" \/><\/figure><\/div>\n\n\n\n<p>In simple words, media queries in CSS are a feature that allows you to modify the look of a website according to some specific constraints or conditions. These constraints are nothing but the system or browser settings of a device. By using media queries, you can create different styles according to the width and height of the viewport or device, its orientation, and resolution.&nbsp;<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/9-great-benefits-to-using-css3\/\">9 Great benefits to using CSS3<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Maximum and Minimum Constraints<\/strong><\/h2>\n\n\n\n<p>The maximum and minimum properties are used to apply a particular style that will work only within your values. You can apply them with either width or height to declare specific values.&nbsp;<\/p>\n\n\n\n<p>Once you pass the maximum property to a media query, the style is applied to the screens whose maximum value is less than what is specified. In this case, CSS automatically assigns the minimum value as 0px.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"386\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/03\/Screenshot-609.png\" alt=\"\" class=\"wp-image-3185\" \/><\/figure><\/div>\n\n\n\n<p>On the other hand, the minimum property gets applied to screens with greater than the specified value. If a device falls below the minimum range set by you, then the style won&#8217;t be applied to it.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/11-useful-free-css-codes-for-web-developers\/\">11 Useful Free CSS Codes for Web Developers<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Using Max and Min Media Queries to Change the Width<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s assume that we set the min-width(device) to 1024px at 100% width of your website. It means that whenever a device width becomes 1024px or greater, the website will set its width to 100%. If one uses a device having, say, 768px width, the website won&#8217;t work at 100% range in this case. Min-width is typically used to design a website for mobile, which usually has a lower width.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"480\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/03\/Screenshot-610.png\" alt=\"\" class=\"wp-image-3186\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-group is-layout-flow\"><div class=\"wp-block-group__inner-container\">\n<div class=\"wp-block-group is-layout-flow\"><div class=\"wp-block-group__inner-container\">\n<pre class=\"wp-block-preformatted\">@media (min-width: 1024px) {<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp; &nbsp;&nbsp;#Example{width: 100%;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp; &nbsp;&nbsp;}<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">}<\/pre>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p>In another case, let&#8217;s set the max-width(device) to 1024px and the width of your website to 70%. In this case, our applied design will work only when a device has a width less than or equal to 1024px. The max-width media queries are used with a desktop-first approach, meaning that the style will first be applied to desktop devices.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@media (max-width: 1024px) {<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp; &nbsp;&nbsp;#Example{width: 70%;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp; &nbsp;&nbsp;}<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Using Max and Min-Width Media Queries Together<\/strong><\/h2>\n\n\n\n<p>Max and min-width media queries can be combined to set your design in a specific range of screen sizes. This is usually done with the &#8220;And&#8221; operator. The &#8220;and&#8217; operator combines two statements and works only when both are true. When you use the &#8220;and&#8221; operator with max and min-width, the range gets set for those values. It means that when both max and min points set by you become true on a device, your website design will automatically apply to it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"490\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/03\/Screenshot-611.png\" alt=\"\" class=\"wp-image-3187\" \/><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">@media screen and (min-width: 768px) and (max-width: 1024px) {<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp; &nbsp;&nbsp;.example{width: 70%;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp; &nbsp;&nbsp;}<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">} <\/pre>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/5-reasons-to-learn-css3\/\">5 Reasons to Learn CSS3<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>In this article, we explained the concept of max and min-width in a simple and essential context. Using max and min-width in media queries helps you develop your web page according to a desktop or a mobile-first approach. It gives you better control and excellent responsiveness to your app or website.<\/p>\n\n\n\n<p><strong>See Also: <a href=\"https:\/\/cssdeck.com\/blog\/implement-a-blur-or-filter-effect-on-an-image-using-css3\/\">Implement a Blur or Filter Effect on an Image Using CSS3<\/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>CSS or Cascading Style Sheet is a language we use to design an HTML document. With CSS, you can add unique styles and develop user interfaces without spending much of your time.&nbsp;<\/p>\n<p>In the recent CSS (CSS3) version, a new technique [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/css-setting-max-media-to-fit-a-phone\/\" title=\"Click to read 'CSS Setting Max Media to Fit a Phone'\">Read Article<\/a><\/p>\n","protected":false},"author":21,"featured_media":3183,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3182"}],"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=3182"}],"version-history":[{"count":3,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3182\/revisions"}],"predecessor-version":[{"id":3246,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3182\/revisions\/3246"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/3183"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}