Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling elements with a dot (.) in the class name

Tags:

css

class

Hay I have an element like this

<span class='a.b'> 

Unfortunately this class name comes from an eCommerce application and cannot be changed.

Can I style a class name with a dot in it?

like

.a.b { } 
like image 213
dotty Avatar asked Aug 10 '10 08:08

dotty


People also ask

How do you style a class name in CSS?

To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.)

What is the use of dot CSS?

The dot(.) and hash(#) both of them are used as a CSS selector. Both selectors are used to select the content to set the style. CSS selectors select HTML elements according to its id, class, type, attribute, etc.

How do you apply a class style rule to an element?

It is needed to stylize HTML elements – including changing colors, fonts, or the size of a text. If you want to use a class, use a full stop (.) followed by the class name in a style block. Next, use a bracket called a declaration block that contains the property to stylize the element, such as text color or text size.

How do you change the class style of an element?

The class name is used as a selector in HTML which helps to give some value to the element attributes. The document. getElementById() method is used to return the element in the document with the “id” attribute and the “className” attribute can be used to change/append the class of the element.


2 Answers

.a\.b { } 

However there could be browsers around that don't support this.

like image 175
RoToRa Avatar answered Oct 21 '22 23:10

RoToRa


Coming very late to this party, but you can use attribute selectors.

In your case, to target the class='a.b' element, you could use:

[class~="a.b"] {...} // or span[class~="a.b"] {...} 

Additionally, here is the full list of attribute selectors.

Attribute Present Selector

// Selects an element if the given attribute is present  // HTML <a target="_blank">...</a>  // CSS a[target] {...} 

Attribute Equals Selector

// Selects an element if the given attribute value // exactly matches the value stated  // HTML <a href="http://google.com/">...</a>  // CSS a[href="http://google.com/"] {...} 

Attribute Contains Selector

// Selects an element if the given attribute value // contains at least once instance of the value stated  // HTML <a href="/login.php">...</a>  // CSS a[href*="login"] {...} 

Attribute Begins With Selector

// Selects an element if the given attribute value // begins with the value stated  // HTML <a href="https://chase.com/">...</a>  // CSS a[href^="https://"] {...} 

Attribute Ends With Selector

// Selects an element if the given attribute value // ends with the value stated  // HTML <a href="/docs/menu.pdf">...</a>  // CSS a[href$=".pdf"] {...} 

Attribute Spaced Selector

// Selects an element if the given attribute value // is whitespace-separated with one word being exactly as stated  // HTML <a href="#" rel="tag nofollow">...</a>  // CSS a[rel~="tag"] {...} 

Attribute Hyphenated Selector

// Selects an element if the given attribute value is // hyphen-separated and begins with the word stated  // HTML <a href="#" lang="en-US">...</a>  // CSS a[lang|="en"] {...} 

Source: learn.shayhowe.com

like image 34
Matija Mrkaic Avatar answered Oct 21 '22 21:10

Matija Mrkaic