{"id":2863,"date":"2024-06-27T13:14:12","date_gmt":"2024-06-27T19:14:12","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=2863"},"modified":"2024-06-27T13:14:14","modified_gmt":"2024-06-27T19:14:14","slug":"has-is-the-god-selector","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/has-is-the-god-selector\/","title":{"rendered":":has() is &#8220;The God Selector&#8221;"},"content":{"rendered":"\n<p>I&#8217;m such a <code>:has()<\/code> selector fanboy in CSS. We&#8217;ve covered it <a href=\"https:\/\/frontendmasters.com\/blog\/tag\/has\/\">many times<\/a>. But Bruce Lawson goes as far as to call it <a href=\"https:\/\/brucelawson.co.uk\/2024\/css-has-the-god-selector\/\">&#8220;The God Selector&#8221;<\/a> because: <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>[It] is omnipotent because it doesn\u2019t require any structural relationship between the thing being checked and the thing being styled.<\/p>\n<\/blockquote>\n\n\n\n<p>In other words, you can select <em>any element<\/em> based on the state of <em>any other element<\/em> with no regard for where they are in the DOM, which is as powerful as it gets in selection. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Imagine it like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-comment\">\/* You're selecting the &lt;html&gt; element\n   when there is *any* popover open. *\/<\/span>\n<span class=\"hljs-selector-pseudo\">:has(<\/span><span class=\"hljs-selector-pseudo\">:popover-open)<\/span> {\n  \n\n  <span class=\"hljs-comment\">\/* Now select buttons *anywhere* on the page\n     that also trigger popovers. *\/<\/span>\n  button&#91;popovertarget] {\n\n  }\n\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m such a :has() selector fanboy in CSS. We&#8217;ve covered it many times. But Bruce Lawson goes as far as to call it &#8220;The God Selector&#8221; because: [It] is omnipotent because it doesn\u2019t require any structural relationship between the thing being checked and the thing being styled. In other words, you can select any element [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2868,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[40,7],"class_list":["post-2863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-has","tag-css"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/06\/god-selector.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=2863"}],"version-history":[{"count":3,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2863\/revisions"}],"predecessor-version":[{"id":2869,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2863\/revisions\/2869"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/2868"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=2863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=2863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=2863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}