Is there any difference between both of them?
Example 1:
a>b{
display: block;
}
Example 2:
a > b{
display: block;
}
Is there any difference between both of them?
Example 1:
a>b{
display: block;
}
Example 2:
a > b{
display: block;
}
CSS is very forgiving. The CSS selectors specification mentiones that whitespaces around combinators (like your >
here) are optional:
The following selector represents a p element that is child of body:
body > p
The following example combines descendant combinators and child combinators.
div ol>li p
It represents a p element that is a descendant of an li element; the li element must be the child of an ol element; the ol element must be a descendant of a div. Notice that the optional white space around the ">" combinator has been left out.
To further back this up, the specification's Grammar section makes this really apparent with an implementation approach:
combinator /* combinators can be surrounded by whitespace */ : S+ | S* [ '>' | '+' | '~' | COLUMN | '/' IDENT '/' ] S* ;
For this reason, the following are all valid as CSS parsers should simply strip the spaces out:
a>b {}
a > b {}
a> b {}
a >b {}
a > b {}
So to answer your question: no, there is no difference.
As for which one you should use, however: that's purely a question of personal preference. For me, I'd opt for a > b
, simply because I feel it makes it easier to read, but if you want to type a>b
or even a > b
it's entirely up to you - although anyone who has to read your code will probably not be your number 1 fan with the latter approach!
There is no such difference. See the snippet below for demo:
.a>.b{
color: red;
}
.c > .d{
color: red;
}
<div class="a">
Class a
<div class="b">
Class b
</div>
</div>
<div class="c">
Class c
<div class="d">
Class d
</div>
</div>
First of all there is no effect space between or not, both will work.
Example will work with following DOM structure:
<a><b></b></a>
There is no difference between the two.