Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the dot mean in CSS?

Can someone explain the difference for these two CSS selectors?

.work-container . h3 { font-size: 14px; margin-top: 0px; font-weight: 600; height: 27px; }  

What is the extra dot in the upper definition?

.work-container h3 { font-size: 14px; margin-top: 0px; font-weight: 600; height: 27px; }  
like image 653
code-gijoe Avatar asked Oct 10 '12 02:10

code-gijoe


People also ask

What is Dot and hash in CSS?

The dot( . ) signifies a class name while the hash ( # ) signifies an element with a specific id attribute. The class will apply to any element decorated with that particular class, while the # style will only apply to the element with that particular id.

What does the period mean in CSS?

To match a specific class attribute, we always start the selector with a period, to signify that we are looking for a class value. The period is followed by the class attribute value we want to match.

Do you need a dot in CSS?

So, recap: to select a html element, the css selector is without a dot, if you need to select a class, you use the dot.

What is the use of DOT in HTML?

The dot prefix indicates that it is a class selector and will match an HTML element which is a member of the given class. To make an element a member of a class, the class name is added to the space separated list given as the value of the class attribute.


2 Answers

Cases

  • Selector start with dot

.class_name signifies class name

  • Two dotted selector separated by space

.outside .inside

means element with .inside class descended from an element with class .outside

  • Two dotted selector without separation

.name1.name2

means element that has both class name1 and name2 eg: class="name1 name2"

Related questions:

  • What does a space mean in a CSS selector? i.e. What is the difference between .classA.classB and .classA .classB?
  • What's the difference between CSS classes .foo.bar (without space) and .foo .bar (with space)
like image 193
Jobin Avatar answered Sep 18 '22 17:09

Jobin


A . prefix usually represents a class selector, but if it's immediately followed by whitespace then it's a syntax error.

If I were to hazard a guess, then it's likely the author meant to say .work-container > h3, but missed the Shift key just as he was about to type the > character (the child combinator).

Your second selector, .work-container h3, simply means any h3 that's contained within an element with a class called work-container.

like image 28
BoltClock Avatar answered Sep 20 '22 17:09

BoltClock