html - Align elements in a fieldset -
i'm trying align combination of labels , inputs. using fieldset > table > tr > td
structure. i've read online typically poor practice, however, i'm having difficult time using css accomplish need.
here sample:
td.right { text-align: right; } fieldset { display: block; margin-left: 2px; margin-right: 2px; padding-top: 0.35em; padding-bottom: 0.625em; padding-left: 0.75em; padding-right: 0.75em; border: 2px groove; }
<fieldset> <table> <tr> <td class="right">date of call:</td> <td><input class="datepicker2" name="calldate"></td> <td class="right">caller code number:</td> <td><input class="codemaker" name="callercodenum"></td> <td class="right">what jurisdiction?</td> <td><input type="text" name="jurisdiction"></td> </tr> <tr> <td class="right">date of offense:</td> <td><input class="datepicker2" name="crimedate"></td> <td class="right">time of offense:</td> <td><input class="timepicker?" name="crimetime"></td> <td class="right">number:</td> </tr> </table> </fieldset>
this renders nicely table formatting (3 label/input combinations first row, , 3 label/input combinations second row). there 3 columns.
any input appreciated.
you can replicate table using css display
property , values table
table-row
table-cell
etc.
there number of reasons why bad practice use tables layout. quick search return dozens of articles on issue.
i see main reasons as: table layouts not semantic; if not displaying tabular data, don't use table. table layouts not accessible - users using screen reader not happy. once used css provide styling layout find easier maintain.
fieldset { display: block; margin-left: 2px; margin-right: 2px; padding-top: 0.35em; padding-bottom: 0.625em; padding-left: 0.75em; padding-right: 0.75em; border: 2px groove; } .table { display: table; } .tr { display: table-row; } .td { display: table-cell; vertical-align: top; } .td.right { text-align: right; }
<fieldset class="table"> <div class="tr"> <div class="td right">date of call:</div> <div class="td"><input class="datepicker2" name="calldate"></div> <div class="td right">caller code number:</div> <div class="td"><input class="codemaker" name="callercodenum"></div> <div class="td right">what jurisdiction?</div> <div class="td"><input type="text" name="jurisdiction"></div> </div> <div class="tr"> <div class="td right">date of offense:</div> <div class="td"><input class="datepicker2" name="crimedate"></div> <div class="td right">time of offense:</div> <div class="td"><input class="timepicker?" name="crimetime"></div> <div class="td right">number:</div> </div> <div class="tr"> <div class="td right">date of call:</div> <div class="td"><textarea rows="5" cols="15"></textarea></div> <div class="td right">caller code number:</div> <div class="td"><textarea rows="5" cols="15"></textarea></div> <div class="td right">what jurisdiction?</div> <div class="td"><textarea rows="5" cols="15"></textarea></div> </div> </fieldset>
Comments
Post a Comment