Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple dots/periods in CSS

Can one of you CSS experts explain this designator (if that's even what you'd call it) to me? I understand the contents, just not the a.button.gold. Two dots?

a.button.gold{
background-color: #b9972f;
}

I am trying to modify a couple of styles on a Wordpress theme and would have a lot more success with it, if I could figure out what is currently happening. Thanks

like image 628
Praesagus Avatar asked Sep 03 '13 04:09

Praesagus


People also ask

What does two dots mean in CSS?

The two dots indicate two classes. I.E. It is selecting all elements with a class of nav AND pull-right it's target HTML would look like this <div class="nav pull-right"></div>

How do I use dots in CSS?

in CSS means it is a class and it can be applied to many elements. # in CSS means it is an ID and it can be applied to one element per page. Without the either, it is a tag, targets all the elements with the tag name. In your syntax, .

What is the dot operator in CSS?

The dot operator is used to create a style class which can then be applied on multiple html elements.

What does the period in front of CSS mean?

Class SelectorsThe period is followed by the class attribute value we want to match. For example, if we wanted all elements with a class of "highlight" to have a different background color, we would use the following CSS rule: .highlight { background-color: #ffcccc; }


2 Answers

The selector simply means select any a element having class .button AS WELL AS .gold so your anchor tag should look like

<a href="#" class="button gold">Hello</a>

Demo

The selector can be also written as element[attr~=val] as @BoltClock Commented like

a[class~="button"][class~="gold"] {
   color: #f00;
}

Demo


Generally the above(Not the selector, but calling multiple classes for a single element method) is also used when you want to apply properties of 2 classes to a single element, so say for example you have .demo having color: green; and .demo2 having font-weight: bold; so using

<p class="demo demo2">Hello, this will be green as well as bold</p>

Will make it green as well as bold. Demo 2

like image 80
Mr. Alien Avatar answered Sep 23 '22 03:09

Mr. Alien


This selector represents an <a> element with two classes, as you can have as many classes (separated with a white-space in the class attribute itself) in CSS as you'd like. The HTML would look like:

<a href="#" class="button gold">Test</a>

If the <a> had three classes you'd just continue the pattern:

<a href="#" class="button gold test">Test</a>

a.button.gold.test {
    color: peachpuff;
}

http://jsfiddle.net/NeqAg/

like image 32
Adrift Avatar answered Sep 25 '22 03:09

Adrift