{"id":28,"date":"2022-11-02T17:31:00","date_gmt":"2022-11-02T17:31:00","guid":{"rendered":"https:\/\/mjonesdesign.co.uk\/blog\/?p=28"},"modified":"2023-02-25T17:32:48","modified_gmt":"2023-02-25T17:32:48","slug":"advanced-css-selectors","status":"publish","type":"post","link":"https:\/\/mjonesdesign.co.uk\/blog\/2022\/11\/02\/advanced-css-selectors\/","title":{"rendered":"<strong>Advanced CSS Selectors<\/strong>"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Class 7: What I Learned This Week\u2026<\/strong><\/h2>\n\n\n\n<p><strong>HTML &amp; CSS Feedback<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It\u2019s a good idea to not use margin in the body section as we can place it with main instead<\/li>\n\n\n\n<li>Floats can\u2019t be contained as they cause the collapsing parent problem. This can be fixed by using \u2018flow-root\u2019 on the parent element<\/li>\n\n\n\n<li>You can use \u2018p:first-of-type:first-letter\u2019 in CSS instead of having to use the span tag in HTML<\/li>\n\n\n\n<li>You can use ctrl + scroll to test different screen sizes by zooming in\/out to see how your work looks<\/li>\n\n\n\n<li>You can\u2019t use vw\/vh as image sizes in html<\/li>\n\n\n\n<li>Span is an inline element, div is a block element<\/li>\n\n\n\n<li>It is a good idea to use the line height in the body section, you can alter it for other elements specifically in different selectors so that it can be overridden<\/li>\n<\/ul>\n\n\n\n<p><strong>Lean Code<\/strong><\/p>\n\n\n\n<p>It is more considerate to others if you are working in a team, such as a job environment, to keep things in order with commented out notes and simple\/no unnecessary code. This is also more sustainable as it uses less energy to load the webpage, less data transferred and less data on people\u2019s computers. Using lean code is more accessible because it makes it easier for assistive technologies to interpret. The nav element acts a div but better as it has semantic meaning as well, therefore it is redundant adding an extra div when the nav already acts as a container.<\/p>\n\n\n\n<p><strong>Advanced CSS Selectors<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use aria label &lt;nav aria-label=\u201dprimary\u201d&gt; if you have more than one navigation section<\/li>\n\n\n\n<li>nav a:nth-of-type(2) means to select the 2<sup>nd<\/sup> anchor element inside of the nav<\/li>\n\n\n\n<li>If list is unordered, a[href=\u201dtoffee.html\u201d] this is an attribute selector<\/li>\n\n\n\n<li>nav[aria-label=\u201dprimary\u201d]<\/li>\n\n\n\n<li>Combinator selector is defined by relationship with sibling elements<\/li>\n\n\n\n<li>Child combinator which selects paragraphs that are direct children of = main&gt;p<\/li>\n\n\n\n<li>General sibling selector is any paragraph which follows the h2 = h2~p<\/li>\n\n\n\n<li>Adjacent sibling combinator selects any paragraph directly after h2+p<\/li>\n\n\n\n<li>Child and adjacent combinator, all paragraphs that are direct children of main following h2 = main&gt;h2+p<\/li>\n\n\n\n<li>Action pseudo classes = p:first-child selects a paragraph if it happens to be a first child<\/li>\n\n\n\n<li>Tree-structural pseudo-classes &#8216;p:last-child&#8217; means all paragraphs that are last children<\/li>\n\n\n\n<li>p:nth-child(3) selects the 3<sup>rd<\/sup> child of any container, main p:nth-child(3) means the 3<sup>rd<\/sup> child of main<\/li>\n\n\n\n<li>p:nth-child(odd) are all paragraphs that are odd children. p:nth-child(even) are all paragraphs that are even children<\/li>\n\n\n\n<li>p:nth-of-type(3) is a tree-structural pseudo-class. Selects not the 3<sup>rd<\/sup> child, but the 3<sup>rd<\/sup> paragraph<\/li>\n\n\n\n<li>p:nth-of-type(odd\/even)<\/li>\n\n\n\n<li>main p:first\/last-of-type selects first or last paragraph in main<\/li>\n<\/ul>\n\n\n\n<p><strong>Attribute Selectors<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>a[href^=\u201dhttps\u201d] is an &lt;a&gt; element where the href attribute value starts with the string \u201chttps\u201d. This is a neat way of selecting all external links<\/li>\n\n\n\n<li>main :not(p) selects everything in main that is not a paragraph. Applies to direct children only<\/li>\n\n\n\n<li>:has(p) are all elements containing paragraphs that are direct children (this is not ready for production sites yet)<\/li>\n\n\n\n<li>h1:has(+h2) selects h1 that is immediately followed by h2. Both are only supported on Chrome so far and again are not ready for production sites<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Class 7: What I Learned This Week\u2026 HTML &amp; CSS Feedback Lean Code It is more considerate to others if you are working in a team, such as a job environment, to keep things in order with commented out notes and simple\/no unnecessary code. This is also more sustainable as it uses less energy to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-design-for-web-content"],"_links":{"self":[{"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":1,"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":29,"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions\/29"}],"wp:attachment":[{"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjonesdesign.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}