Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding between checkbox and label

Tags:

css

For the CSS gurus out there, this markup outputs a checkbox with a label Value1 to its right, but Value1 is too close to the checkbox.

<dd id="rr-element">    <label for="rr-1">       <input type="checkbox" value="1" id="rr-1" name="rr[]">       Value 1    </label> </dd> 

So I'm trying to create a padding-right effect to the right of the checkbox, but it's not working. The checkbox and label move together. How can I target the checkbox only or its text only so I create a padding gap?

dd label input {    padding-right:100px; } 
like image 516
jblue Avatar asked Oct 06 '10 22:10

jblue


People also ask

How do you put a space between checkbox and label?

Use margin-right .

How do you put a space between a checkbox and text in HTML?

If the intent of the user is to bring some more space between check box "box" and its corresponding text, you can use "&npsp;" in the Text content of the checkbox. Hope that helps.

How do you put a space between two checkboxes in bootstrap?

You can use margin left ( ml-x ), margin right ( mr-x ) or padding left ( pl-x ), padding right ( pr-x ) classes of bootstrap-4 or alpha. Where x is any number (1, 2, 3 etc).

How do I make a checkbox in HTML?

The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices. Tip: Always add the <label> tag for best accessibility practices!


2 Answers

Use margin-right. padding is inside the element, and often acts funny with input elements because they are rendered using the OS's native input components, and are a mess to customize in general.

JSFiddle here

like image 99
Pekka Avatar answered Sep 20 '22 02:09

Pekka


No unclickable gap between checkbox and label.
No line wrap disconnection of the checkbox and label.
No spaces added by code indentations.
More readable.

<dd id="rr-element">    <input type="checkbox" value="1" id="rr-1" name="rr[]">    <label for="rr-1">Value 1</label> </dd> 

<style> #rr-element {     white-space: nowrap; }  #rr-element label {    padding-left: 0.4em; } </style> 
like image 37
NOYB Avatar answered Sep 18 '22 02:09

NOYB