html - Equal-width form labels with arbitrary horizontal rules -


i have horizontal label: <input> style form. labels need equal widths, dynamic - based on longest label in form. normally, i'd solve series of display: table/row/cell elements, need horizontal rule separating some of these rows.

display: table not play non-row/cell elements inside it.

the core form structure:

<form>     <div class="group">       <span>test</span>       <div class="field">         <input type="text">       </div>     </div>     <hr>     <div class="group">       <span>test long</span>       <div class="field">         <input type="text">       </div>     </div>     <div class="group">       <span>test</span>       <div class="field">         <input type="text">       </div>     </div>   </form> 

the css:

* { box-sizing: border-box; } html, body { width: 100%; }  form {   display: table;   border-collapse: collapse;   border-spacing: 0;   width: 100%;   border: 1px solid red; }  .group {   display: table-row; }  span {   display: table-cell;   background: #ddd;   padding: 0 10px 0 0;   white-space: nowrap;   width: 1px; }  input, hr {   width: 100%; } 

the label widths work i'd expect, yet hr cannot fill 100% width. can right width making position: absolute, lose spacing between rows. can make display: table-row no longer have control on spacing.

jsbin

this funny one.

i don't know how strict design here ok solution.

hr{   display:table-cell;   padding:10px 0;   border:none;   box-sizing:content-box;   background:black;   height:1px;   background-clip:content-box; } 

using table-cell on hr can expand full width, little trick on padding , background-clip can have simple horizontal line. if want take further can add image background , use repeat-x expand in full width.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -