CSS ::first-line pseudo selector

The ::first-line pseudo-element is for applying styles to the first line of an element. Imagine a paragraph that is several lines long.

::first-line allows you to style that first line of text. You could use it to make it larger or set it in small-caps as a stylistic choice. The amount of text targeted by this pseudo-element depends on the several factors like line length, viewport width, font-size, letter-spacing, word-spacing. As soon as the line breaks, the text after that is no longer selected. Note that there is no actual DOM element being selected here.

This pseudo-element only works on block-level elements (when display is set to either block, inline-block, table-caption, table-cell). If set on an inline element, nothing happens, even if that inline element has a line break within it.

CSS ::first-letter pseudo selector

::first-letter is a pseudo element which allows you to style the first letter in an element, without needing to stick a tag around that first letter in your HTML.

While no tags are added to the DOM, it is as if the targeted first letter were encompassed in a tag. You can style that first letter as you would a real element with.

The pseudo element only works if the parent element is a block container box. In other words, it doesn’t work on the first letter of display: inline; elements.

If you have both a ::first-letter and ::first-line on an element, the first letter will inherit from the first line styles, but styles on the ::first-letter will overwrite when styles conflict.

If you generate content with ::before, the first letter or punctuation character, whether it’s part of the original text node or created with generated content, will be the target.

CSS enabled pseudo selector

The :enabled pseudo-class in CSS selects focusable elements that are not disabled, and therefore enabled. It is only associated with form elements (input, select, textarea). Enabled elements include ones in that you can select, that you can enter data into, or that you can focus on or click.

In theory, :enabled should match an a, area, or link with href attributes, but browsers don’t seem to handle that scenario. You can style button, input, textarea, optgroup, option and fieldsets that are not disabled. When menu is supported, we should also be able to target command and li‘s that are children of menu, if not disabled.

You would also think that elements with contenteditable and tabindex attributes would be selectable with the :enabled pseudo-class.

Descendent Selector in CSS

A descendant selector in CSS is any selector with white space between two selectors without a combinator.

Descendant means anywhere nested within it in the DOM tree. Could be a direct child, could be five levels deep, it is still a descendant. This is different than a child combinator which requires the element to be the next nested level down.

The descendant selector is the most expensive selector in CSS. It is dreadfully expensive—especially if the selector is in the Tag or Universal Category.

CSS :disabled pseudo selector

The :disabled pseudo-class selector provides conditional styling to HTML elements that can receive user input, when the elements have the disabled attribute.

It is defined in the CSS Selectors Level 3 spec as a “UI element state pseudo-class”, meaning it is used to style content based on the user’s interaction with an input element.

Elements that can receive the disabled attribute include button, input, textarea, optgroup, option and fieldset.

There are two valid syntaxes for setting this attribute: either disabled=”disabled” or (in HTML5) simply the disabled Boolean keyword. An element is disabled if it can’t be activated (e.g. selected, clicked on or accept text input) or accept focus. Such an element can be styled using the :disabled pseudo-class selector.