CSS: Vertical column layout without
后端 未结 3 491
终归单人心
终归单人心 2021-01-13 15:36

Ok, I leaned html & css back in 2001. I was used to do something like this (To create a website with a \"vertical-column\" layout):




        
3条回答
  •  没有蜡笔的小新
    2021-01-13 16:13

    Below is a basic grid I cobbled together you can use with any size website. You'll need to clear the floats on the columns with either overflow hidden or a clearfix. If your project doesn't need to support IE7 you can use box-sizing border-box to add padding to your columns, otherwise add an extra element inside each column for padding.

    Whilst I can appreciate that making columns was super easy with tables that was pretty much the only thing they were better for layout wise.

    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%; }
    

提交回复
热议问题