{"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=IQoJb3JpZ2luX2VjEM3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJHMEUCIQDidD4Dhh%2FMDM3%2B99fCppr80%2BbokgySTyX533ok%2FxS8LgIgZWce1MMLnOAEqcpyaClXuL3whWFTT7cAZfWVQi%2BAo9MqwgUIlv%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAFGgwyNzM1NzAxOTU0MzMiDKC%2Be%2B0cJLTKTQpAgCqWBb5O%2BL05lZrqqDSwZ%2FyzBusIj0j7p7LoerfBgL96iGLWlqkcbl%2FJC%2Fa0GshX79Pv7Te0p4SGdLw3ULj4xvMO3vtKVdE9xiukly6L8bKG%2BOt6GclsSBUKFuL1WvFjpLs8WeiwuIYAeb3M8fP9Iu6PqKEzpE5mesjUfGXx78N1yvOiKrkDlLtt7j5AoNfJZlFB23s404v1p4K3zug%2BaTqgMdLYea5NQWNcK5yQ4WJT5fRq0N8RNsgyS4dauM%2FU4YjeYnTArggKSyeZBkNcoEMvD%2BP%2F6uNqs2avxDvNsxScUgBESaexnKihumHQgy%2Bpri5HKjwEBAyRMLtUKnkWdZmdSdo9oxYTcXCjoL1FAx3wiw0lpgx2rTZVU6oEOxwpxQUs%2FddCGep9Y5WNyVcSOVPSpKG23pjPnfFp59q%2F%2BWbc5sWCIpl9b7nH6zumZMhW20m3557Glg2ahd6bphmpDiiLD3D%2B9tKHTp2ql2owmLFld2ADFEnQ7%2B0BDVFDDmAfhv5OHMX%2BWtZacsuRAoGNtlcGF%2FDein8cpaduKyBLG8wzueHA9GN3Y3%2Fodh2MGFrAkaUX0ezGcq7g8U6Tmpxn7R6p58zeLOFQ6SZccZQMYTsDOzOfkToAOGYtidsDocPm5%2FvUqDgSHC1TAg1hGIfJQEq%2Bk4DSykBF3n5CgrVK4peBy5q2PGYUV3AlHttsyxnmut%2BA6S1JADiZ4LEvRQYaklysCX2kPJHs4SZ3KKJ0U1m3VSFQuIiqwUauwi4OrwdHipiW7PnW6LcVh7n0v4YQdti02SRyhvFb837tt6LfnH6PRYs%2B9VyTxd8CBx7FIxVPROwjSZHQsIBXysLySWcjWMEiGg8XY%2BGA8abZWSJq6ZMjZqa2nLobiU0MMIPS%2FtUGOrEBCC4TwD1TyEHCxWUaaJuoiPYsukbcnpasWDiB0R4OCGWIfCSoJfAMd%2FNrDqhmZRHD4iN0HvSrF5QEZf8CROUM746tJtUgthEBjzDcCRiHuzTHbpczVLwIV2a4EHxHmtsVaH1Ob7F%2BBIJUZ4IJBNPN2Mb2ya7adlrV%2BJLCccvv2U5ZLwUDh6o1W%2Ff5HgvLTcyG3caRoSAYet91gb4PlkYIwxdpiZWu52kAdwHojiTXamUF&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47UVHCMPVT3%2F20261002%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20261002T133349Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=c97cbbccac4cf0a9c5cd280eba03998dcefb67c34f67b581fa343290da77f370\" 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=IQoJb3JpZ2luX2VjEM3%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSJHMEUCIQDidD4Dhh%2FMDM3%2B99fCppr80%2BbokgySTyX533ok%2FxS8LgIgZWce1MMLnOAEqcpyaClXuL3whWFTT7cAZfWVQi%2BAo9MqwgUIlv%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAFGgwyNzM1NzAxOTU0MzMiDKC%2Be%2B0cJLTKTQpAgCqWBb5O%2BL05lZrqqDSwZ%2FyzBusIj0j7p7LoerfBgL96iGLWlqkcbl%2FJC%2Fa0GshX79Pv7Te0p4SGdLw3ULj4xvMO3vtKVdE9xiukly6L8bKG%2BOt6GclsSBUKFuL1WvFjpLs8WeiwuIYAeb3M8fP9Iu6PqKEzpE5mesjUfGXx78N1yvOiKrkDlLtt7j5AoNfJZlFB23s404v1p4K3zug%2BaTqgMdLYea5NQWNcK5yQ4WJT5fRq0N8RNsgyS4dauM%2FU4YjeYnTArggKSyeZBkNcoEMvD%2BP%2F6uNqs2avxDvNsxScUgBESaexnKihumHQgy%2Bpri5HKjwEBAyRMLtUKnkWdZmdSdo9oxYTcXCjoL1FAx3wiw0lpgx2rTZVU6oEOxwpxQUs%2FddCGep9Y5WNyVcSOVPSpKG23pjPnfFp59q%2F%2BWbc5sWCIpl9b7nH6zumZMhW20m3557Glg2ahd6bphmpDiiLD3D%2B9tKHTp2ql2owmLFld2ADFEnQ7%2B0BDVFDDmAfhv5OHMX%2BWtZacsuRAoGNtlcGF%2FDein8cpaduKyBLG8wzueHA9GN3Y3%2Fodh2MGFrAkaUX0ezGcq7g8U6Tmpxn7R6p58zeLOFQ6SZccZQMYTsDOzOfkToAOGYtidsDocPm5%2FvUqDgSHC1TAg1hGIfJQEq%2Bk4DSykBF3n5CgrVK4peBy5q2PGYUV3AlHttsyxnmut%2BA6S1JADiZ4LEvRQYaklysCX2kPJHs4SZ3KKJ0U1m3VSFQuIiqwUauwi4OrwdHipiW7PnW6LcVh7n0v4YQdti02SRyhvFb837tt6LfnH6PRYs%2B9VyTxd8CBx7FIxVPROwjSZHQsIBXysLySWcjWMEiGg8XY%2BGA8abZWSJq6ZMjZqa2nLobiU0MMIPS%2FtUGOrEBCC4TwD1TyEHCxWUaaJuoiPYsukbcnpasWDiB0R4OCGWIfCSoJfAMd%2FNrDqhmZRHD4iN0HvSrF5QEZf8CROUM746tJtUgthEBjzDcCRiHuzTHbpczVLwIV2a4EHxHmtsVaH1Ob7F%2BBIJUZ4IJBNPN2Mb2ya7adlrV%2BJLCccvv2U5ZLwUDh6o1W%2Ff5HgvLTcyG3caRoSAYet91gb4PlkYIwxdpiZWu52kAdwHojiTXamUF&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47UVHCMPVT3%2F20261002%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20261002T133349Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=6922bbb2957616bc9e3fa43297d5918ac411af93436d0904220867f03c9a84a1\" 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}]}}