April 13, 2012

How to control a <label> with CSS?

Question by AAA

I have this snippet:

      <label>&nbsp;</label><a id="whatever" 
      onclick="addmore('field_whatever', 'What's up?');">The deal is?</a><br/>

How do i use CSS to add space on the top or the bottom. I am able to do it for margin-left but it won’t work for margin-top nor margin-bottom.

Thanks

Answer by Starx

labels are by default inline. They will not respond on top/bottom margin. You have to tell them to display as block/inline-block .

Like this

label { 
    display: inline-block;
    margin: 20px 0;
}

Additionally, your anchor has an un-escaped quote. Correct it as this

<a id="whatever" 
      onclick="addmore('field_whatever', 'What's up?');">The deal is?</a>

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!