0

HTML

<div class="containerDiv">
    <p>Test</p>
    <input type="checkbox" checked="checked" />
</div>

CSS

.containerDiv 
{
    width:600px;
}

.containerDiv p 
{
    margin: 10px 0px 10px 10px;
    float: left; 
    width: 500px;
}

.containerDiv input[type='checkbox']
{
    float: right;
    margin: auto 10px;
}

Hello,

I have a div with a text (the text can be very long) in a p-tag and a input. I want vertical center the input right next to the text, but float: left and margin: auto 10px doesn't work.

freshbm
  • 5,540
  • 5
  • 46
  • 75

4 Answers4

1

You can place your checkbox in absolute position and use top:50% minus the checkbox height. So you don't need to float:right this element but give it a right position. See this demo: http://jsfiddle.net/4wXuC/1/

otinanai
  • 3,987
  • 3
  • 25
  • 43
0

For giving margin try margin: 10px auto; instead of margin: auto 10px;

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
Atif Azad
  • 527
  • 1
  • 4
  • 15
-1

Use label instead of p and set the line-height of the label to the total height of the input.

simbo
  • 374
  • 4
  • 6
-1
 <div style="width: 55px;">
<p style="float: left; margin: 0px 0px 10px 10px; width: auto;">Test</p>
<input checked="checked" style="float: right; margin: 5px auto;" type="checkbox">
 </div>
Atif Azad
  • 527
  • 1
  • 4
  • 15