html - display table-cell 50% width not working -
i'm trying create nicely formatted form using display: table, ran bit of problem , can't seem work out.
here's code:
.table-container { width: 100%; margin: 10px auto; display: table; border-collapse: collapse; outline: 1px solid black; } .form-row { display: table-row; border: 1px solid #393939; width: 100%; float: left; border-bottom: 1px solid #393939; border-collapse: collapse; } .header { background-color: yellow; } .twenty { width: 20%; } .twentyfive { width: 25%; } .thirty { width: 33%; } .thirty:last-child { width: 34%; } .fourty { width: 40%; } .fifty { width: 50%; } .sixty { width: 60%; } .seventy { width: 70%; } .cell { display: table-cell; padding: 10px 20px; border-right: 1px solid #393939; vertical-align: middle; border-collapse: collapse; } .first { border-left: 1px solid #393939; }
<form> <div class="table-container"> <span class="form-row header">date solicitant</span> <span class="form-row"> <span class="cell fifty first"><input type="text" placeholder="nume" id="nume" name="nume" /></span> <span class="cell fifty last"><input type="text" placeholder="prenume" id="prenume" name="prenume" /></span> </span> <span class="form-row"> <span class="cell twentyfive first">tip act de identitate<br /><input type="radio" name="tip-act" value="bi">bi <input type="radio" name="tip-act" value="ci">ci <input type="radio" name="tip-act" value="pasaport">pasaport</span> <span class="cell twentyfive"><input type="text" name="serie-act" id="serie-act" placeholder="serie" style="width: 25%";/> <input type="text" name="numar-act" id="numar-act" placeholder="numar" /></span> <span class="cell twentyfive"><input type="text" name="eliberat" id="eliberat" placeholder="eliberat de" /></span> <span class="cell twentyfive last"><input type="date" name="eliberat-data" id="eliberat-data" placeholder="la data de (zz/ll/aaaa)" /></span> </span> <span class="form-row"> <span class="cell thirty first"><input type="text" name="cnp" id="cnp" placeholder="cod numeric personal" /></span> <span class="cell thirty"><input type="text" name="loc-nastere" id="loc-nastere" placeholder="locul nasterii" /></span> <span class="cell thirty">starea civila:<br /><input type="radio" name="stare-civila" value="casatorit(a)">casatorit(a) <input type="radio" name="stare-civila" value="necasatorit(a)">necasatorit(a) <input type="radio" name="stare-civila" value="divortat(a)">divortat(a) <input type="radio" name="stare-civila" value="vaduv(a)">vaduv(a) </span> </span> </div> </form>
my problem that, although 2nd , 3rd rows displayed ok, cells taking entire row space, on 1st row, cells take small part of row. it's simple thing i'm overlooking, i've been trying solve while , fresh pair of eyes help.
thanks in advance!
the problem have float in class .form-row
. need have property in each cell, , add class box-sizing: border-box
. thus, cell class have following css:
.cell { display: table-cell; padding: 10px 20px; border-right: 1px solid #393939; vertical-align: middle; border-collapse: collapse; float:left; box-sizing:border-box; }
jsfiddle here: http://jsfiddle.net/7m879c5l/
Comments
Post a Comment