{"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=IQoJb3JpZ2luX2VjEP3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJGMEQCIB59gurgDgQhvV%2BlZwX1Ed%2BrPHu45Zg6GQky4YuZzyN9AiBlfFjbBWViOo31hKu%2BiUmfq%2Fi5LKWRT3zXzPCzXia3FCrBBQjG%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAUaDDI3MzU3MDE5NTQzMyIMuizRS9M%2FtiKtdW6xKpUFEjEETX%2BgnqX7dIS2mSj%2FzMkVZnVK1Aa7DPtC536nX%2FTxSD%2BFXI%2F6P8JrRiWTRbvx%2FbloUw5ntewe3lztQf9PCDe4n4miQW2NuEqtfMix7zBFzI0fttpmCep6sqaWaPvc0q2zPDCxqepp5uee3UAxvOIdwwrbDBA1WrlTtSXSE4Fq8GVEDi2BWyU0wZ3uR7X07lk4BWL9u%2Bl6ZJtH2zR6MeCi1tQlDxv%2BfsYrZ1tzvjx0yRP%2FptNjYfGemlbcQTxCS%2FGYY1VUAZAvjPcyu71YAItlR8HoNdZKfhan1Mh8UvmseHlkOis%2FAs0iFtdAW9QnqseKYfRoovteFK9QHpcl%2BPpKsgi27ogINOa6h3ZLu1zcuvQli2OYXhKGQfyoG%2FFYeYsYfe%2FwlX%2F83TQJWYxtpfjzLk%2B3nvCW8WzlNLbkmQQkFQ0DmGtn1lsE%2FywVmndAZLE7oJrHnuKpT5tJudGe85JJ8ge%2Bod%2BzfhmIM0Heq3k%2F%2BrsEAdxggY%2BZ%2BsNpcALJIXugReO5b8XZwpUM10lmQQqNhuS%2BSy4ZCNCTJz7BzPuKjZcpQdxNs%2FPUgtGNl7qADOq2NryW9Ig9HevXsE69f%2Ft9YrBbWlq2aIM0dCmm6%2Bsow7Ejf2lmoySGicffwFgG5TSCheJTginEpo%2Fd%2FEBPq%2BnJ%2BvGh3RuDU0hduy9MVcEUd3vKVs%2FYWQGU7MMzsVTOGnCAd27l12A1ukmgO7AO5GAUWDdZ9oCkB2Bwpd7TtKsZGUhpPH%2FNn8tr8E17Tl12whGRABgjy6cN8PyvQJ6hw12qlSVEZNJ4HBYxvLz5FAfT2Xtbv%2BjoRcEar2c4C7vERiAR6RUcRYvfh34KJrCiLgj9poGfHQi3k8kJGXRFEa%2BAefuoUzC9vp7RBjqyARQYdSthWyK3mWq7TW5xEo4WNcfq%2Fk%2FfD0wq22KftZO0aCYI4v2UnDWVcSKR5o6DF5AVVUHscOmh586nPQ%2FGuSA1QmqaVlvmwBrRq7GVU2yIm3%2BSRIlYgQvrKTDImkncYzh%2Fq13ebYQpO1oeCaCSBVbdB7%2FQsBcxlYhBv8zypy7In6HBTo4Dr5RYWBMdbVnSESdLUpT0lhOCidzDpFqbzYDwcjxttRp9oGt7ZbseWfYZbkg%3D&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47U7VFSLGR5%2F20260609%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260609T052922Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=e427ccdd0a4882596c71e4bab6346e46c0cfc23136bd76d2c29f8cc21a49fff0\" 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=IQoJb3JpZ2luX2VjEP3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJGMEQCIB59gurgDgQhvV%2BlZwX1Ed%2BrPHu45Zg6GQky4YuZzyN9AiBlfFjbBWViOo31hKu%2BiUmfq%2Fi5LKWRT3zXzPCzXia3FCrBBQjG%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAUaDDI3MzU3MDE5NTQzMyIMuizRS9M%2FtiKtdW6xKpUFEjEETX%2BgnqX7dIS2mSj%2FzMkVZnVK1Aa7DPtC536nX%2FTxSD%2BFXI%2F6P8JrRiWTRbvx%2FbloUw5ntewe3lztQf9PCDe4n4miQW2NuEqtfMix7zBFzI0fttpmCep6sqaWaPvc0q2zPDCxqepp5uee3UAxvOIdwwrbDBA1WrlTtSXSE4Fq8GVEDi2BWyU0wZ3uR7X07lk4BWL9u%2Bl6ZJtH2zR6MeCi1tQlDxv%2BfsYrZ1tzvjx0yRP%2FptNjYfGemlbcQTxCS%2FGYY1VUAZAvjPcyu71YAItlR8HoNdZKfhan1Mh8UvmseHlkOis%2FAs0iFtdAW9QnqseKYfRoovteFK9QHpcl%2BPpKsgi27ogINOa6h3ZLu1zcuvQli2OYXhKGQfyoG%2FFYeYsYfe%2FwlX%2F83TQJWYxtpfjzLk%2B3nvCW8WzlNLbkmQQkFQ0DmGtn1lsE%2FywVmndAZLE7oJrHnuKpT5tJudGe85JJ8ge%2Bod%2BzfhmIM0Heq3k%2F%2BrsEAdxggY%2BZ%2BsNpcALJIXugReO5b8XZwpUM10lmQQqNhuS%2BSy4ZCNCTJz7BzPuKjZcpQdxNs%2FPUgtGNl7qADOq2NryW9Ig9HevXsE69f%2Ft9YrBbWlq2aIM0dCmm6%2Bsow7Ejf2lmoySGicffwFgG5TSCheJTginEpo%2Fd%2FEBPq%2BnJ%2BvGh3RuDU0hduy9MVcEUd3vKVs%2FYWQGU7MMzsVTOGnCAd27l12A1ukmgO7AO5GAUWDdZ9oCkB2Bwpd7TtKsZGUhpPH%2FNn8tr8E17Tl12whGRABgjy6cN8PyvQJ6hw12qlSVEZNJ4HBYxvLz5FAfT2Xtbv%2BjoRcEar2c4C7vERiAR6RUcRYvfh34KJrCiLgj9poGfHQi3k8kJGXRFEa%2BAefuoUzC9vp7RBjqyARQYdSthWyK3mWq7TW5xEo4WNcfq%2Fk%2FfD0wq22KftZO0aCYI4v2UnDWVcSKR5o6DF5AVVUHscOmh586nPQ%2FGuSA1QmqaVlvmwBrRq7GVU2yIm3%2BSRIlYgQvrKTDImkncYzh%2Fq13ebYQpO1oeCaCSBVbdB7%2FQsBcxlYhBv8zypy7In6HBTo4Dr5RYWBMdbVnSESdLUpT0lhOCidzDpFqbzYDwcjxttRp9oGt7ZbseWfYZbkg%3D&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47U7VFSLGR5%2F20260609%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260609T052922Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=a2354721487cec7142c824d9cf81ad5180958d38ab69364bf03fab6ec8096ecf\" 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}]}}