Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Targeting a class value that begins with a space

I want to make a CSS selector for a class which starts with a whitespace, but I don't know how. For example: <table class=" example">…</table>.

like image 758
Dumb Noob Avatar asked Jan 05 '23 01:01

Dumb Noob


1 Answers

Any leading or trailing spaces in the value of a class attribute are meaningless for targeting purposes. This: class=" example" is equivalent to this: class="example".

There is no need for a special selector that factors in the space.

From the HTML 5 spec:

2.4.7 Space-separated tokens

A string containing a set of space-separated tokens may have leading or trailing space characters.

Space characters are necessary, however, for separating multiple values in a class attribute.

3.2.5.7 The class attribute

The attribute, if specified, must have a value that is a set of space-separated tokens representing the various classes that the element belongs to.

like image 58
Michael Benjamin Avatar answered Jan 08 '23 06:01

Michael Benjamin