html - CSS: Vertical column layout without <table> -
ok, leaned html & css in 2001. used (to create website "vertical-column" layout):
<html> <head> <title>vertical-column layout</title> </head> <body> <table id="doc" > <!-- header --> <tr> <td id="header" colspan="3"><!-- header code/php include --></td> </tr> <!-- / header --> <!-- / content --> <tr> <td id="col1" name="menu"><!-- content code/php include --></td> <td id="col2" name="content_left"><!-- content code/php include --></td> <td id="col3" name="content_right"><!-- content code/php include --></td> </tr> <!-- / content --> <!-- footer --> <tr> <td id="footer" colspan="3"><!-- header code/php include --></td> </tr> <!-- / footer --> </table> </body> </html> easy, automatically aligned way want, no css headache etc. life then. however, not long ago, read approach should no longer used. going try new way using bunch of div's, w3c & w3c's validation not using block elements inline elements...wtf!!!
so...my frustration lead me ask guys:
how? how accomplish in "modern way"...as easy possible? html 5 has better way?
why? why should not use table approach "vertical column layout" on website?
below basic grid cobbled can use size website. you'll need clear floats on columns either overflow hidden or clearfix. if project doesn't need support ie7 can use box-sizing border-box add padding columns, otherwise add element inside each column padding.
whilst can appreciate making columns super easy tables pretty thing better layout wise.
html:
<!doctype html> <html lang="en-us"> <head> <meta charset="utf-8"> <title></title> </head> <body> <header></header> <div class="content grid"> <div id="col1" class="col s1of3"></div> <div id="col2" class="col s1of3"></div> <div id="col3" class="col s1of3"></div> </div> <footer></footer> </body> </html> css:
.grid { } .grid .col { float: left; } .grid .col.s1of1 { width: 100%; } .grid .col.s1of2 { width: 50%; } .grid .col.s1of3 { width: 33.33333333%; } .grid .col.s2of3 { width: 66.66666666%; } .grid .col.s1of4 { width: 25%; } .grid .col.s3of4 { width: 75%; } .grid .col.s1of5 { width: 20%; } .grid .col.s2of5 { width: 40%; } .grid .col.s3of5 { width: 60%; } .grid .col.s4of5 { width: 80%; }
Comments
Post a Comment