September 21, 2012

Style will not apply without using a ','

Question by Norman

I just noticed, using the css code below ignores the .input.cmp bit :

.create input.cmp, input.email, input.pswd, input.pswda{}

while using the code below (with a , before) works fine.

.create ,input.cmp, input.email, input.pswd, input.pswda{}

How is this happening? Is this the right way to do it? Or am I doing something wrong here.

I previously used to use an ID instead of class and things worked fine without the first ‘,’

Answer by Starx

This seems to be like a misunderstanding and logical error .

  1. .create input.cmp, selects input.cmp inside .create
  2. .create ,input.cmp, are two different selectors .create and input.cmp

Here is an simple example:

.create input.cmp selects the input element ONLY in the following HTML

<div class="create">
   <input type="text" class="img" />
</div>

Where as, .create ,input.cmp selects both div and input elements.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!