{"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 loading=\"lazy\" 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=IQoJb3JpZ2luX2VjEE8aCWV1LXdlc3QtMSJHMEUCIQDxM6YiQF4yBmDtwowOJC6b0jigPQSzmCDDla3pVBEergIgd%2Ffi0R0XBZ1L5xyadjv6O9UY5bu1ij51I7HVNFl9wxwquAUIGBAFGgwyNzM1NzAxOTU0MzMiDMyrKtx%2FbKagKA8HGiqVBR%2FPei8m5kWAVB2X0nEDS5gp8EdxqcqrBLskmcQan6kHrsejKotuoe174dOd51ZpYrGX%2Fp2mMA7a0bAUetkMWYbJGx6GKK6lI4Id3oPdJlcMIkIfz1EzwTR6IitURBtHbfGmuSULSq7j7TIKEjF0gXsvRlqpmD6%2Fx6tgea1GlDur0AdaxsJpkBlvK0jXy3b5%2FAvlqIFT%2F3kL7W2N0Rk5BNoADSgEnAHJPCmFiinF8mCYW3Cp%2FBFZfYcFyNNcdWCdko0i6mAYDlqSN09nqXTpeiYgGH7NZgixaAuXcYvY0gZ2%2Fc5x02Vu7BIH5LdoXMhfAATm9MzlLfyTHF25DqXXDuoQe9Ex361M6obJh84c%2FDiHJCNTlLM17iNDg2Y%2BC2Ff4C4xXyN6qR49gTUk2tSsrRKtpEmikEyD7KF%2B3P8KNoKcRXpIAO%2B7kf6FpU8Ax6ezJoFBANOWAjwQuJ8yxXt7sJMkApCCaHpdj7Ss2T6oyR5S9KQP0ryOZVJ1R8JoWDN8Tlm67FqKqcAM7nd7AUmeAHcMtwHd%2FizNt7bnzljpE35dDs32f1hsM%2FigyoOAj6hRLsej61WaJySmYmsTHuu%2BytEVJw0TuFToLMvcoAYqKReMMroRmu1Dz6784BjEER65S1noS0W4NwczeKdhm1nAS6ubM%2BLjOi8SWw67NOWaMOUDUra3EpHOsi%2FLlwhbtJswh7TPJAEubpojAUcSBHU6ruGsZmBK9oJ%2F31kvp4z6iyV%2Fwlu85AS5%2BEV1KF0s1yuXz1b7JmgSlA4qk8ZwLQ9aKY%2B%2B981elKc8LvvwKnbJ0baOYXzcvnYVDdSKeOohDVd6w3hsGZoLJ3jy1saPjSzsjliuc5g3M%2FIMQ5DA2%2BsfDPkaxu%2B%2FQe8wspGXzwY6sQGbk%2BWiM5%2Ff%2B172cLYKeWgeM6VB%2BopX0%2Bbdhu74zBwjtEZ86%2BySIw1XhJWPicF2nUMkZK2afQj7sR3mBzEyXqFC6yAMmKmnyKg%2B9o64KuoXH6BIL6NJ2RIMx9kJ%2FRquyXLloQQAbr2idsvomYUXehzfAZORzrKFod4P5a2A55bi%2BlokZBOm1g%2BNAu%2BKqpWFjWmYXF6fw4Ww8KWCpnX3yWvW1GuOCp9o9zpMRaVTAL%2Fz%2F0A%3D&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47UUQAL7HMR%2F20260420%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260420T064421Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=1b96817ae7cf9c1de8a4fd78f24189f4f04a87733f1253085a9ed7aadaa2466e\" alt=\"\" width=\"100\" height=\"97\" \/><a href=\"https:\/\/www.w3schools.com\/css\/css3_mediaqueries.asp\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" 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=IQoJb3JpZ2luX2VjEE8aCWV1LXdlc3QtMSJHMEUCIQDxM6YiQF4yBmDtwowOJC6b0jigPQSzmCDDla3pVBEergIgd%2Ffi0R0XBZ1L5xyadjv6O9UY5bu1ij51I7HVNFl9wxwquAUIGBAFGgwyNzM1NzAxOTU0MzMiDMyrKtx%2FbKagKA8HGiqVBR%2FPei8m5kWAVB2X0nEDS5gp8EdxqcqrBLskmcQan6kHrsejKotuoe174dOd51ZpYrGX%2Fp2mMA7a0bAUetkMWYbJGx6GKK6lI4Id3oPdJlcMIkIfz1EzwTR6IitURBtHbfGmuSULSq7j7TIKEjF0gXsvRlqpmD6%2Fx6tgea1GlDur0AdaxsJpkBlvK0jXy3b5%2FAvlqIFT%2F3kL7W2N0Rk5BNoADSgEnAHJPCmFiinF8mCYW3Cp%2FBFZfYcFyNNcdWCdko0i6mAYDlqSN09nqXTpeiYgGH7NZgixaAuXcYvY0gZ2%2Fc5x02Vu7BIH5LdoXMhfAATm9MzlLfyTHF25DqXXDuoQe9Ex361M6obJh84c%2FDiHJCNTlLM17iNDg2Y%2BC2Ff4C4xXyN6qR49gTUk2tSsrRKtpEmikEyD7KF%2B3P8KNoKcRXpIAO%2B7kf6FpU8Ax6ezJoFBANOWAjwQuJ8yxXt7sJMkApCCaHpdj7Ss2T6oyR5S9KQP0ryOZVJ1R8JoWDN8Tlm67FqKqcAM7nd7AUmeAHcMtwHd%2FizNt7bnzljpE35dDs32f1hsM%2FigyoOAj6hRLsej61WaJySmYmsTHuu%2BytEVJw0TuFToLMvcoAYqKReMMroRmu1Dz6784BjEER65S1noS0W4NwczeKdhm1nAS6ubM%2BLjOi8SWw67NOWaMOUDUra3EpHOsi%2FLlwhbtJswh7TPJAEubpojAUcSBHU6ruGsZmBK9oJ%2F31kvp4z6iyV%2Fwlu85AS5%2BEV1KF0s1yuXz1b7JmgSlA4qk8ZwLQ9aKY%2B%2B981elKc8LvvwKnbJ0baOYXzcvnYVDdSKeOohDVd6w3hsGZoLJ3jy1saPjSzsjliuc5g3M%2FIMQ5DA2%2BsfDPkaxu%2B%2FQe8wspGXzwY6sQGbk%2BWiM5%2Ff%2B172cLYKeWgeM6VB%2BopX0%2Bbdhu74zBwjtEZ86%2BySIw1XhJWPicF2nUMkZK2afQj7sR3mBzEyXqFC6yAMmKmnyKg%2B9o64KuoXH6BIL6NJ2RIMx9kJ%2FRquyXLloQQAbr2idsvomYUXehzfAZORzrKFod4P5a2A55bi%2BlokZBOm1g%2BNAu%2BKqpWFjWmYXF6fw4Ww8KWCpnX3yWvW1GuOCp9o9zpMRaVTAL%2Fz%2F0A%3D&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47UUQAL7HMR%2F20260420%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260420T064421Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=6e59e4fb424b595d72290731ddabf463c7fe0b916cf5ed45afb86234655f596a\" 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}]}}