Keep the label vertically aligned in a form - HTML CSS CSS Form

HTML CSS examples for CSS Form:Form

Description

Keep the label vertically aligned in a form

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
body {<!--   w ww. ja v a2  s  . co  m-->
   margin:0;
}

.row {
   display:table;
   padding:4px 0;
}

.label, .input {
   display:table-cell;
   vertical-align:middle;
}

.label {
   width:100px;
   padding-right:11px;
   text-align:right;
}

.input {
   height:26px;
   padding:3px;
}
</style> 
 </head> 
 <body> 
  <div class="row"> 
   <div class="label"> 
    <label>Lorem ips</label> 
   </div> 
   <div class="input"> 
    <input type="text" placeholder="one"> 
   </div> 
  </div> 
  <div class="row"> 
   <div class="label"> 
    <label>Lorem ipsum dol</label> 
   </div> 
   <div class="input"> 
    <input type="text" placeholder="two"> 
   </div> 
  </div> 
  <div class="row"> 
   <div class="label"> 
    <label>Lorem ipsum dolor sit </label> 
   </div> 
   <div class="input"> 
    <input type="text" placeholder="three"> 
   </div> 
  </div> 
  <div class="row"> 
   <div class="label"> 
    <label>Lorem ipsum dolor sit amet, consectetu</label> 
   </div> 
   <div class="input"> 
    <input type="text" placeholder="four"> 
   </div> 
  </div> 
  <div class="row"> 
   <div class="label"> 
    <label>Lorem ipsum do</label> 
   </div> 
   <div class="input"> 
    <textarea placeholder="Large text area"></textarea> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials