Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between .class > .class and .class .class

I just want to know the difference between:

.class .class{
font-size:14px;
}

VS:

.class > .class{
font-size:14px;
}

Is the same thing?

like image 234
user2154508 Avatar asked Mar 15 '14 05:03

user2154508


People also ask

What does .class .class mean in CSS?

Definition and Usageclass selector selects elements with a specific class attribute. 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.

What is the difference between class and class?

Class is a Java class just like Object and String are classes. In short, both are essentially the same, but you can keep a reference of a String. class object using the Class class.

What is the difference between class and Div?

A div is a container tag that is used to define a division or a section in an HTML document, whereas a class is an attribute that specifies actions to be taken to one or more elements. When using a class in CSS you have to specify the HTML elements you want it to affect by using a dot(.)

What is plus in CSS?

The “+” sign selector is used to select the elements that are placed immediately after the specified element but not inside the particular elements.


1 Answers

No, they aren't the same - the first example is a descendant selector, the second is a direct child selector.


.class .class will target all elements with the class .class which derive from any element which has the class .class, e.g

<div class="class">
 <div class="other">
    <div class="class"> This is targeted. </div>
 </div> 
</div>

jsFiddle example


.class > .class will only target direct children of elements with the class .class, e.g

<div class="class">
   <div class="other">
      <div class="class">This isn't targeted.</div>
   </div> 
   <div class="class">
      <div class="class">This is targeted, as it is a direct child.</div>
   </div>    
</div>

jsFiddle example.

like image 140
dsgriffin Avatar answered Nov 03 '22 16:11

dsgriffin