{"id":321,"date":"2021-06-08T18:58:47","date_gmt":"2021-06-08T17:58:47","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/?page_id=321"},"modified":"2021-06-10T12:12:33","modified_gmt":"2021-06-10T11:12:33","slug":"media-queries","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/css\/media-queries\/","title":{"rendered":"Media Queries"},"content":{"rendered":"<p>The display of <strong>responsive pages<\/strong> <img decoding=\"async\" class=\"alignright wp-image-196\" src=\"https:\/\/glow-prod-sh.s3.eu-west-1.amazonaws.com\/sh\/public\/ahscomputinghtml\/uploads\/sites\/3275\/2021\/06\/05211152\/sqa-ah-150x150.png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&#038;X-Amz-Security-Token=IQoJb3JpZ2luX2VjEMn%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJGMEQCIGG%2BFeO%2BjnSKhSeXsmHiuie2PEOyYMzOiFyacHHqLwhNAiALKFtj1eSejMIKULje93GEHLgSbzRFm4uUztIWk4UF7irCBQiS%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAUaDDI3MzU3MDE5NTQzMyIMKr%2BuhVqiN%2FV4YwS2KpYFkZg5ZPX9Z1jAVSGn7lj5f9n3xjjb2EPfdRgTZjdQS2TXwXe6hE%2FjqTZMxy0Ku48w5aBQO%2BAgmxOZ57oZPZ1rkvMxO9vsI32xniYx96iOLsI8MbMYlCpQcY1S99G3mkIH4aaodXQua694%2FQQFXK3h5%2FRvOS%2B9OhKEJQN09L9XA3kjY8p0tYbh1wZbRPKEVYp%2Btt8Wry9EQBmYMKy9dWZRiw5Mz2MH6wTvhktngYqkjA2CiXPdT2HBGSNRY2WIWrlHnPqiQEu0%2FC3uCAcJGjOzdYgy78kMs9zV14EaxL%2BKczx%2BoV9HHBGZd1uTR%2FWeOGuliTlRgdNBi0jbQIM1nkbdBZ5Nm0IytJrPgiZ3NplilyrvS0Ow%2FlZd5ouFwoJjkrlsFyyqACEcdBLqCwZ4lXEWOtcsAHE1Ne4WtYkUCCpqCmW2024uXXGAF5lEw0EhoPFv%2B3%2FpYRYkKBL3keTJuCpFkq8SCZ06keFHQZ%2FVdFoMkfkCqs3nxPksPizH3FMVUxZMvUnx9cA2LflQXopEl11hL7fXhlgAwyUAIyCNknK%2Fa7vAybO4vBbghwoMcr4YgxSbz7zaDY4mdg%2BNvSLC3efKveqsU56UZzXTrVYRhKzgQtv8J3CotCPbm3j%2BZicCFzffv7He3ApbhMT0iz7ygRkXoEgZ9RCMdx%2FxZnb8BW%2FHr6AyC%2Bl2AgMAV3R%2FH3IJgle3mCWgcwjJMBucdvzmBIQJUnDMqkFpPo86JAiu0I4JuHbkLMKSR7eUCp%2B7JOOh2l8FOhWyaeh10%2Ba6ZgUYDgKV30qy9keqNQUW1ALj9oTTpJ88d7FwllGbFxQkxrti8npQYEzB4NrrZsOYeMkzrpvdk9p819vXe9a7isVcdmmhHUW4TkAPZeAwpqDu1gY6sgE%2FpBCRxNJNSPNu2iCVdcMdm53220UhGBoBOtJA9yqpyKgMA4YEfp0vdmgAWDAsy00iT9aBhAtyoBYqrAIWXk8JMc2%2BEq9GMd9UCBlizdRF8she4xUD6kcNE7Vc19vD6%2Bpgwk6jd%2F891bSh9MC4Pd1rfdT%2Fh27kFfEnc5r4W00jKigdOmTTbfCbsCf%2BsIKedJFHO4RjstZIdbrGmeq9HMKdH7uDUE1Bm0BWSnlGNrMLQQm6&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47U3NWMBDOA%2F20261023%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20261023T173524Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=4506759fff69886c0749f8efc77b3b75572207609058c03d3f0be1dc518903cc\" alt=\"\" width=\"100\" height=\"97\" \/><a href=\"https:\/\/www.w3schools.com\/css\/css3_mediaqueries.asp\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"image-59 alignright\" src=\"https:\/\/glow-prod-sh.s3.eu-west-1.amazonaws.com\/sh\/public\/ahscomputinghtml\/uploads\/sites\/3275\/2021\/06\/03210120\/w3schools-150x150.png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&#038;X-Amz-Security-Token=IQoJb3JpZ2luX2VjEMn%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJGMEQCIGG%2BFeO%2BjnSKhSeXsmHiuie2PEOyYMzOiFyacHHqLwhNAiALKFtj1eSejMIKULje93GEHLgSbzRFm4uUztIWk4UF7irCBQiS%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAUaDDI3MzU3MDE5NTQzMyIMKr%2BuhVqiN%2FV4YwS2KpYFkZg5ZPX9Z1jAVSGn7lj5f9n3xjjb2EPfdRgTZjdQS2TXwXe6hE%2FjqTZMxy0Ku48w5aBQO%2BAgmxOZ57oZPZ1rkvMxO9vsI32xniYx96iOLsI8MbMYlCpQcY1S99G3mkIH4aaodXQua694%2FQQFXK3h5%2FRvOS%2B9OhKEJQN09L9XA3kjY8p0tYbh1wZbRPKEVYp%2Btt8Wry9EQBmYMKy9dWZRiw5Mz2MH6wTvhktngYqkjA2CiXPdT2HBGSNRY2WIWrlHnPqiQEu0%2FC3uCAcJGjOzdYgy78kMs9zV14EaxL%2BKczx%2BoV9HHBGZd1uTR%2FWeOGuliTlRgdNBi0jbQIM1nkbdBZ5Nm0IytJrPgiZ3NplilyrvS0Ow%2FlZd5ouFwoJjkrlsFyyqACEcdBLqCwZ4lXEWOtcsAHE1Ne4WtYkUCCpqCmW2024uXXGAF5lEw0EhoPFv%2B3%2FpYRYkKBL3keTJuCpFkq8SCZ06keFHQZ%2FVdFoMkfkCqs3nxPksPizH3FMVUxZMvUnx9cA2LflQXopEl11hL7fXhlgAwyUAIyCNknK%2Fa7vAybO4vBbghwoMcr4YgxSbz7zaDY4mdg%2BNvSLC3efKveqsU56UZzXTrVYRhKzgQtv8J3CotCPbm3j%2BZicCFzffv7He3ApbhMT0iz7ygRkXoEgZ9RCMdx%2FxZnb8BW%2FHr6AyC%2Bl2AgMAV3R%2FH3IJgle3mCWgcwjJMBucdvzmBIQJUnDMqkFpPo86JAiu0I4JuHbkLMKSR7eUCp%2B7JOOh2l8FOhWyaeh10%2Ba6ZgUYDgKV30qy9keqNQUW1ALj9oTTpJ88d7FwllGbFxQkxrti8npQYEzB4NrrZsOYeMkzrpvdk9p819vXe9a7isVcdmmhHUW4TkAPZeAwpqDu1gY6sgE%2FpBCRxNJNSPNu2iCVdcMdm53220UhGBoBOtJA9yqpyKgMA4YEfp0vdmgAWDAsy00iT9aBhAtyoBYqrAIWXk8JMc2%2BEq9GMd9UCBlizdRF8she4xUD6kcNE7Vc19vD6%2Bpgwk6jd%2F891bSh9MC4Pd1rfdT%2Fh27kFfEnc5r4W00jKigdOmTTbfCbsCf%2BsIKedJFHO4RjstZIdbrGmeq9HMKdH7uDUE1Bm0BWSnlGNrMLQQm6&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47U3NWMBDOA%2F20261023%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20261023T173524Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=a44c2af6bc6bde7ebf1a853e6e75c09c8839f1dea36c20d84dd30a98ff5f67f3\" alt=\"\" width=\"50\" height=\"47\" \/><\/a>will change depending on the device or window on which they are to be viewed.<\/p>\n<p>Common uses for responsive pages is for:<\/p>\n<ul>\n<li>printing on paper\/PDF<br \/>\n(hiding unnecessary page elements, using black on white text)<\/li>\n<li>screens with narrower displays (tablets\/smartphones)<br \/>\n(replacing a horizonal navigation bar with a vertical, or hamburger menu)<\/li>\n<\/ul>\n<p>Within the CSS, default values are written first, with media queries defined underneath. When coding media queries, only the changes are styled.<\/p>\n<pre class=\"brush: css; title: CSS Syntax; notranslate\" title=\"CSS Syntax\">\r\n@media not|only mediatype and (expressions) {\r\n    CSS Code;\r\n}\r\n<\/pre>\n<p>Three media types are in the Advanced Higher course: <strong>all, screen<\/strong> and <strong>print <\/strong>(there is also a &#8220;speech&#8221; type for screenreaders that read out the page contents).<\/p>\n<p>Only the <strong>max-width<\/strong> media feature is required (other features include min-width and orientation).<\/p>\n<p>Note: only the media query declaration itself is included in the Advanced Higher course.<\/p>\n<h1>Examples<\/h1>\n<h2>Navigation Bars<\/h2>\n<p>A <strong><a href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/html\/horizontal-navigation-bars\/\">horizontal navigation bar<\/a><\/strong> uses the <strong>float<\/strong> and <strong>width<\/strong> properties to display <strong>li<\/strong> elements alongside each other, suitable for a wide screen display.<\/p>\n<pre class=\"brush: css; title: CSS Horizontal Navigation Bar; notranslate\" title=\"CSS Horizontal Navigation Bar\">\r\nnav ul {\r\n        list-style-type:none;\r\n}\r\n \r\nnav ul li {\r\n        float:left;\r\n        width:80px;\r\n        text-align:center;\r\n}\r\n \r\n \r\nnav ul li a {\r\n    display:block;\r\n    padding:8px;\r\n    background-color:wheat;\r\n    border: 1px solid black;\r\n    text-decoration:none; \r\n}\r\n \r\nnav ul li a:hover {\r\n    background-color:#000;\r\n    color:white;\r\n}\r\n<\/pre>\n<p>For screen displays under 600 pixels wide, the height of the <strong>nav<\/strong> container is increased, and each navigation <strong>li<\/strong> is increased to the full width of the display so they appear underneath each other:<\/p>\n<pre class=\"brush: css; title: CSS; notranslate\" title=\"CSS\">\r\n@media screen and (maxwidth:600px) {\r\n    nav {\r\n        height: 125px;\r\n    }\r\n    nav ul li {\r\n        width:100%;\r\n        height:20px;\r\n        font-size:8pt}\r\n    }\r\n<\/pre>\n<h2>Printing<\/h2>\n<p>Light coloured text on a dark background may work well on a display, but not so well on paper.<\/p>\n<p>Items suitable for displaying on screen may not be needed for printing &#8211; eg when printing a receipt.<\/p>\n<pre>@media print { \n    * { \n        color: black;\n        background-colour: white; \n    }\n\n    .screenonly {\n        display: none;\n    }\n[\/css]<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The display of responsive pages will change depending on the device or window on which they are to be viewed. Common uses for responsive pages is for: printing on paper\/PDF (hiding unnecessary page elements, using black on white text) screens with narrower displays (tablets\/smartphones) (replacing a horizonal navigation bar with a vertical, or hamburger menu) Within the CSS, default values are written first, with media queries defined underneath. When coding<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/css\/media-queries\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":78,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-321","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/comments?post=321"}],"version-history":[{"count":6,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/321\/revisions"}],"predecessor-version":[{"id":376,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/321\/revisions\/376"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/78"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/media?parent=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}