Layout with fixed header and footer, fixed width sidebar and flexible content

后端 未结 3 734
-上瘾入骨i
-上瘾入骨i 2020-12-23 10:31

I\'m trying set up a layout that will look like this: \"enter

I want to use twitter bo

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 11:04

    The magic is in box-sizing:border-box;. For compatibility with Firefox, chrome<10, and safari<5.1, add the -webkit- and -moz- prefixes. IE supports it as of 8.0.

    
    
        
            
            very structured layout
            
        
        
            
            
    left: width = 250px, height = 100%

    fiddle

    edit: after Andres' solution made me realize I could achieve greater compatibility, I messed around a bit and came up with an alternate solution, which I think is more intuitive as well. It doesn't work in IE7, but it does work in IE8.

    The page is the same as the above, with the only change being that the CSS is replaced with this:

    *      {margin:0; padding:0;}
    body   {background:#fff;}
    #main  {background:#888; position:absolute; top:40px; bottom:60px; width:100%;}
    #head  {background:#f8f; position:absolute; width:100%; height:40px;}
    #left  {background:#ff8; position:absolute; width:250px; height:100%; overflow:scroll;}
    #right {background:#8f8; margin-left:250px; height:100%; overflow:scroll;}
    #foot  {background:#f88; position:absolute; bottom:0; width:100%; height:60px;}
    

    fiddle

    Note that, for both versions, #head and #foot need to have an overflow property other than visible if their content would otherwise extend off the page.

提交回复
热议问题