Proper terms and vocabulary for segments and components of selectors

Can you identify the proper terminology for the segments of CSS selectors that are divided by commas?

    body.foo .login , body.bar .login { ... }
/*                  |
           Section 1   |  Section 2         */

And what term is used for the elements within those segments that are separated by combinators (such as spaces, +, >, etc)?

    body.foo .login , ... { ... }
/*          |
     Part 1       |       Part 2    */

Answer №1

What is the proper term for the segments of CSS selectors that are separated by commas?

These segments are referred to as complex selectors. The entire comma-separated list is known as a selector-list.

Within those segments, what is the term for the elements separated by combinators (spaces, +, >, etc)?

These elements are known as compound selectors.

So, a selector-list consists of one or more complex selectors separated by commas, and each complex selector is composed of two main parts: compound selectors, and combinators. It may also include pseudo-elements if needed.

Compound selectors were previously known as "sequence of simple selectors". Similarly, complex selectors were just called "selectors". It's advised to use the new terms as they are clearer, less cumbersome, and more precise compared to the older terminology.


Since we're on the topic, here are the other definitions...

  • A simple selector serves as a fundamental component of selectors. It can be any of the following:

  • As mentioned earlier, a compound selector (formerly known as "sequence of simple selectors") is a series of simple selectors not divided by a combinator:

    a:not([rel="external"]):hover
    
  • A combinator acts as another essential component of selectors. It's a symbol or token that separates two compound selectors, establishing a relationship between the elements represented by them. Currently, there are four combinators in use:

    • Descendant combinator:

      article p
      
    • Child combinator:

      /* 
       * The extra spaces in between are whitespace,
       * and are therefore insignificant.
       */
      ul > li
      
    • Adjacent sibling combinator:

      header + section
      
    • General sibling combinator:

      h2 ~ p
      

    More combinators might be introduced in future specifications.

  • A complex selector (previously termed as "selector") is a complete string comprising compound selectors linked by combinators:

    nav[role="main"] > ul:first-child > li
    
  • The element at the end, or the only one, of a complex selector is known as the subject, representing the element to be styled or matched. In the previous example, the subject is li.

  • The term selector has been broadened to encompass several components like simple selector, compound selector, complex selector, and selector-list for simplicity and conciseness. Context should indicate which specific type of selector is being referred to.

Additional notes:

  • The term "key selector" was coined by browser vendors for internal selector implementations but isn't an official term. It's commonly used to mean "subject of the selector," as implementations typically identify matches based on the subject of the selector.

  • The term "pseudo-selector" was created by authors to blend pseudo-classes and pseudo-elements but lacks official recognition. It's advisable not to use this term as it confuses distinct concepts under a single label, leading to unnecessary confusion.

  • Pseudo-elements (::pseudo-element) aren't simple selectors, so they can't match actual elements directly. However, they are considered selectors for parsing purposes and can appear at the end of complex selectors in a list.

  • In CSS, a standard style rule comprises a selector and a declaration block.

  • Namespace prefixes aren't standalone selectors but may be added to certain selectors like type selectors, universal selectors, and attribute selectors to match namespaced components within a document.

  • Specificity currently pertains to individual complex selectors. When matching rules, all complex selectors that match an element are considered for specificity calculations. If multiple complex selectors match an element, the most specific one dictates the calculation outcome.

    Some level 4 selectors may complicate specificity issues, including :is() and enhanced :not(), along with of S notation in advanced :nth-child() pseudo.

Answer №2

The guidelines provide specific language for this:

A selector is a series of simple selectors connected by combinators. A pseudo-element can be added to the end of the selector.

A series of simple selectors is a chain of simple selectors without any combinators between them. It always starts with a type selector or a universal selector, with no other type or universal selectors allowed in the series.

A simple selector can be a type selector, universal selector, attribute selector, class selector, ID selector, or pseudo-class.

Combinators include whitespace, ">" (greater-than sign), "+" (plus sign), and "~" (tilde). Whitespace can separate combinators from the surrounding simple selectors. Only certain characters like "space," "tab," "line feed," "carriage return," and "form feed" are considered whitespace

There are slight differences in terminology between CSS 2 and 3

The basic definitions have been updated; what was known as a simple selector in CSS2 is now referred to as a sequence of simple selectors, while the term "simple selector" now refers to the components within that sequence

Answer №3

The components delineated by commas are known as selectors.

Inside a selector, there exist simple_selectors and combinators.

Refer to this resource for more information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Auto-scrolling text box cursor movement

My query is quite similar to the topic discussed in this thread on automatic newline in textarea. However, my situation involves multiple textareas with a 1-row attribute, making it seem like writing on air due to the absence of visible borders (I've ...

The elements within <header> and <footer> tags will always remain at the top of the page unless specifically

While working on creating semantically correct HTML, I included a header and footer in my document. The structure of the document looks like this: ... Currently, the header, main, and footer take up 100% of the height. I want t ...

Choose various div elements and modify their background colors

I have a PHP loop where I am creating multiple divs dynamically. Here is the code snippet: <?php for ($i=0; $i<=9; $i++) { for ($j=0; $j<=9; $j++) { echo "<div class=\"bg\" id=\"aaa".$i."&bsol ...

Having issues with my Bootstrap navigation dropdown - any suggestions on what I might be overlooking?

I'm having trouble getting the bootstrap dropdown and button to function properly when the menu collapses on tablet or mobile view. Below is my HTML code for the navigation: <nav class="navbar navbar-default navbar-fixed-top"> <div c ...

Having trouble accessing listview capabilities in jquerymobile?

I am currently delving into the world of jquerymobile. I am experimenting with a sample project where I aim to showcase a listview. Below is the code that I have been working on. <!doctype html> <html> <head> <link rel="stylesheet" h ...

Achieving a 100% width input with Flexbox: Tips and tricks for success

Check out this flexbox form I created using bootstrap 4: https://jsfiddle.net/kkt0k2bs/1/ I have implemented a media query to adjust the form elements for smaller screens. For larger displays, I want the form items to be displayed inline. However, on sm ...

Add a transition or animation effect to the <details> element as it closes

I am experimenting with adding a transition effect to the details element when it opens and closes: details { height: 1em; transition: height 2s; border: 1px solid; overflow: hidden; white-space: pre; } details[open] { height: 6em } <det ...

Crafting a gap between a component and its border

Currently, I am faced with the challenge of creating spacing between an element and its outermost border. To clarify, I aim to incorporate two borders in between the element itself and the external boundaries of the box-model box. This will allow me to lev ...

Limit the container's height to be no more than the height of the

Seeking input on good and bad practices in CSS/HTML/jQuery, I recently asked a question about determining when it is appropriate to use jQuery to set container dimensions. The responses I received were helpful (view them here). Realizing that jQuery may n ...

The CSS dropdown menu appears in a horizontal layout rather than vertical

** body { background-color: #9cb4c0; background-size: 100% 100%; } .div-1 { float: right; padding: 20px 10px; } h2 { text-align: right; ...

Can you explain the distinction between using single and double quotes in my JavaScript and CSS code?

Is there a significant distinction between using single or double quotes in JS and CSS? Does it depend on personal preference, or are there certain instances where one is preferred over the other? In W3Schools, they employ single quotes for url('&apo ...

Align columns to the right and left using Bootstrap

It should be simple enough, but I can't seem to find my mistake. Goal: The entire markup should be centered with a width of col-10. Within the same 10-column width, there should be two divs each taking up 50% of the space. Using Bootstrap 5, for so ...

The behavior of CSS position: sticky varies depending on whether the user is scrolling up or scrolling down

I am experiencing an issue in my Vue CLI app where a component with the position: sticky CSS property is being partially hidden under the top of the browser when scrolling down, but works correctly when scrolling up. This behavior is also observed on my Ga ...

How can I establish the conversion from pixels to em units?

According to a source I found, 1 em is equivalent to 16px. You can read more about it here. Despite setting the font-size to 100% in the body and using font-size: 1em, the standard font size in my Jekyll site remains 12px. Curious? Visit my Jekyll site a ...

Accessing .js and .css libraries from shared views in ASP.NET Core can be restricted

I am currently developing a simple application on ASP.NET core 3.1, and I'm facing a basic problem that I can't seem to solve. The menu of the application is located in a Shared view called _Layout.cshtml. I load .js and .css libraries in this v ...

Centering the menu on the screen

I need help aligning the menu bar in the center. I have attempted to use text-align:center; but it is not working. You can view the website here. Any guidance would be appreciated. Thank you. <nav style="text-transform: uppercase;" id="site-navigation" ...

Error encountered while attempting to input text into an element using Selenium and Python: ElementNotInteractableException - Keyboard cannot reach element

from selenium import webdriver browser = webdriver.Firefox() # Opens Firefox webbrowser browser.get('https://protonmail.com/') # Go to www.protonmail.com website loginButton = browser.find_element_by_css_selector('#bs-example-navbar-collaps ...

NodeJS for CSS Parsing and Selecting

Can anyone recommend a NodeJS library similar to https://github.com/alexdunae/css_parser? I have tried using https://github.com/visionmedia/css, but it doesn't fulfill all my requirements. For example, when I parse the following CSS: .behavior1 {co ...

Creating a fixed navigation bar that stays at the top of the page when scrolling

I am trying to create a navigation bar similar to the one seen on W3School's website. I would like the navigation bar to overlap the header when scrolling down, and for the header to appear above the nav bar when scrolling back to the top. Despite m ...

Choose either nth-child or nth-of-type within a nested element

Here is the HTML code snippet: <div class="homepage-body"> <a href="#"> <div class="homepage-item"> <div class="homepage-icon"></div> <div class="homepage-text"> Test1 </di ...