Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indenting multiline labels

Tags:

css

I have the following automatically-generated HTML:

http://jsfiddle.net/BrV8X/

What is the advised way, using CSS, to indent the label so that there's some white space under the radio button?

like image 425
Roberto Aloi Avatar asked Aug 16 '11 10:08

Roberto Aloi


People also ask

How do I indent multiple lines in HTML?

If you prefer using [spacebar] to indent your code rather than using [tab], you can select multiple lines by holding the [alt] key and clicking on the beginning of each line you want to indent. Then, you can press [spacebar] and all the selected lines will be affected. omg it moves!

How do you indent the second line of a paragraph in CSS?

Output: Method 2: By making the position relative to the first line, set the text-indent to -26px and padding-left value to 26px. Here in this example, we have made the position of the second line relative to the first line. So the second line is indented/aligned according to the first line.

Can HTML tags be multiline?

To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.


3 Answers

label {
    display: block;
    margin-left: 20px;
}
input {
    float: left;
    margin-left: -20px;
    margin-right: 7px;
}

Here's the fiddle: http://jsfiddle.net/hrfmt/ . Play with the values.

EDIT:

If all the browsers you need to support can understand display: inline-block, use that instead of float.

like image 114
Joseph Silber Avatar answered Sep 23 '22 00:09

Joseph Silber


label {
   position:relative;
   padding-left:20px;
   display:block;
}

label input[type=radio] {
   position:absolute;
   top:4px;
   left:0px;   
}

http://jsfiddle.net/BrV8X/4/

like image 26
shanethehat Avatar answered Sep 20 '22 00:09

shanethehat


Here's an example of how to do that without resorting to floats. You'll have to do some magic with negative margins with this approach.

input {
    display: inline-block;
    margin-right: -100px;
    /* The 2 below properties are just for "correct" vertical placement of the button. */
    margin-top: 5px;
    vertical-align: top;
}
label {
    display: inline-block;
    margin-left: 100px;
    margin-right: -100px;
}
div {
    /* Just some spacing between the radio buttons. */
    margin-bottom: 5px;
}

http://jsfiddle.net/4osbp0mo/2/

like image 24
aross Avatar answered Sep 19 '22 00:09

aross