{"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=IQoJb3JpZ2luX2VjEF0aCWV1LXdlc3QtMSJHMEUCIF2Oh2Q%2BOvfqkoRUYuEeSbTPwXugeuFbN4WBMCd2UL9gAiEA9MA0tfixZupvVUfmiQoFkJKFV185oxzRhUhH9ars%2FykqtwUIJhAFGgwyNzM1NzAxOTU0MzMiDNsA2JMlXwAFMDKqGSqUBbA7qAVd0Bp0emVSYrg%2FBEiu7pxFdROUEysv%2BBKVWUUp9QI2ONfCY78dCzrx30iyMURBA6ImjVkEN8%2BdFk5eNBA3F4mu3SB%2FW9ZwmUye6t8WXb6rI%2FgChp5F5ivxdgFtfTNuzq1hEG30qnTCU1AsbT5%2FboR%2FI8kCtfKkgaHDp07ajulz6kk21FZ%2FTb6URyMp44fxcnpsTPTJZ5dqYDZ6lTq%2FiekhWysfpR1N3sHGZ8CQwHrx9r%2F0nrbpqQ1f6zIr60ub5YSN2%2F%2F3kenXE2UH1cUtQZYUkzXrswJc5czw1t96I%2Ban7ZjdF%2F%2BdzYo7jK3qJlTTUelx3V1M6ncHZI18XKZhXFi4IS%2FT6hezlZ%2FMB5RlUrZOPMyHHpqmWR0rSuyGNeYI0Ev90kH4syOaFLGtdltUKUDsnk9WFLE3a1hPxUFj8Ng4X1mJMlfVAbuJ8T%2FYwa140kY5ercq%2Fdv3oithjeCD0tvcpfVIKVuk%2F8qbuZVq5cjEigFroTXP4aUHk37ZY9pUdXmD8%2BIB1aW7wWRHh2Qc1rj8iwZcQ7UbFPdTig6aHKW2TSgye%2FTRPTGSnOujwSwkqIGSff9uneKjy8tSbc0Ro8Us%2BdLc6grDgdJKkegpu6wXDiYkLkVpFmOt7cJ8Jfa4MWhaLOl2aXn6dElfWSXajImJc9hWugb1s9QI0sTSXbw18DN2y66x6zVMGOsrmBzFzLYKmkdwNJKEJPiB2wG%2Bh%2BK4N64TdFzIHMNDhytI8S0uXDHd5zHuuPb6U9LXCnZMJwG8duolnUbpJe1T%2FvrGp5Ok8sQCgMWrzub4KKSLlRrrCzZ4jD%2F4vTCU42Yt5hBOplKm%2FzzpFRswNjC3s2uOgZPr07xf7Web05Bisqd%2BaGCiZzDXwZTTBjqxASmc0yJBpEQG4lBefHyaAxNWR5g6fL4MIGSUBWLpgsLTdxG%2FxmaKp%2Fe2oYudZ6IF9f0pjlGvt6whF26pvkOVlLgIkcSKFD7qk%2B7bVmiC4Wsi0jvJcQ3V%2FVrc4u04zMcoEcA8u4U9hOdL241iCBqbglXMH2K0FyReTzHEPkAmTWaCTuSmdN%2FqftRXNEyMptKFEYdnU5y%2F2mLYf6M6Ou8y708DJqPt8WlGMZ7Ue7X8nawJcw%3D%3D&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47U5VBQ7PK2%2F20260725%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260725T211905Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=fea7b810d126d540513b4867cb6f770c8f32ad75ed85ab59556b4f74453e8813\" 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=IQoJb3JpZ2luX2VjEF0aCWV1LXdlc3QtMSJHMEUCIF2Oh2Q%2BOvfqkoRUYuEeSbTPwXugeuFbN4WBMCd2UL9gAiEA9MA0tfixZupvVUfmiQoFkJKFV185oxzRhUhH9ars%2FykqtwUIJhAFGgwyNzM1NzAxOTU0MzMiDNsA2JMlXwAFMDKqGSqUBbA7qAVd0Bp0emVSYrg%2FBEiu7pxFdROUEysv%2BBKVWUUp9QI2ONfCY78dCzrx30iyMURBA6ImjVkEN8%2BdFk5eNBA3F4mu3SB%2FW9ZwmUye6t8WXb6rI%2FgChp5F5ivxdgFtfTNuzq1hEG30qnTCU1AsbT5%2FboR%2FI8kCtfKkgaHDp07ajulz6kk21FZ%2FTb6URyMp44fxcnpsTPTJZ5dqYDZ6lTq%2FiekhWysfpR1N3sHGZ8CQwHrx9r%2F0nrbpqQ1f6zIr60ub5YSN2%2F%2F3kenXE2UH1cUtQZYUkzXrswJc5czw1t96I%2Ban7ZjdF%2F%2BdzYo7jK3qJlTTUelx3V1M6ncHZI18XKZhXFi4IS%2FT6hezlZ%2FMB5RlUrZOPMyHHpqmWR0rSuyGNeYI0Ev90kH4syOaFLGtdltUKUDsnk9WFLE3a1hPxUFj8Ng4X1mJMlfVAbuJ8T%2FYwa140kY5ercq%2Fdv3oithjeCD0tvcpfVIKVuk%2F8qbuZVq5cjEigFroTXP4aUHk37ZY9pUdXmD8%2BIB1aW7wWRHh2Qc1rj8iwZcQ7UbFPdTig6aHKW2TSgye%2FTRPTGSnOujwSwkqIGSff9uneKjy8tSbc0Ro8Us%2BdLc6grDgdJKkegpu6wXDiYkLkVpFmOt7cJ8Jfa4MWhaLOl2aXn6dElfWSXajImJc9hWugb1s9QI0sTSXbw18DN2y66x6zVMGOsrmBzFzLYKmkdwNJKEJPiB2wG%2Bh%2BK4N64TdFzIHMNDhytI8S0uXDHd5zHuuPb6U9LXCnZMJwG8duolnUbpJe1T%2FvrGp5Ok8sQCgMWrzub4KKSLlRrrCzZ4jD%2F4vTCU42Yt5hBOplKm%2FzzpFRswNjC3s2uOgZPr07xf7Web05Bisqd%2BaGCiZzDXwZTTBjqxASmc0yJBpEQG4lBefHyaAxNWR5g6fL4MIGSUBWLpgsLTdxG%2FxmaKp%2Fe2oYudZ6IF9f0pjlGvt6whF26pvkOVlLgIkcSKFD7qk%2B7bVmiC4Wsi0jvJcQ3V%2FVrc4u04zMcoEcA8u4U9hOdL241iCBqbglXMH2K0FyReTzHEPkAmTWaCTuSmdN%2FqftRXNEyMptKFEYdnU5y%2F2mLYf6M6Ou8y708DJqPt8WlGMZ7Ue7X8nawJcw%3D%3D&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47U5VBQ7PK2%2F20260725%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260725T211905Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=9dcabeaf885d52bfb5e952023027e1e9b7559e2d0b3f9f4d7e06a17ff9ec0b80\" 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}]}}