CSS 3 column liquid layout with fixed center column

后端 未结 4 1186
一个人的身影
一个人的身影 2021-02-04 12:09

I want to make for my marketing site a 3 column layout that has images in the top banner.

I want to have a liquid left/right side with a fixed center. The html would

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 12:41

    Is this helpful?

    CSS Only Demo

    jQuery Demo(Cross Browser Compatible)

     
     
    *{ margin:0; padding:0; } #bannerCenter{ background:#ffffd; width: 500px; float:left; } #pixelLeft{ background:#999; width: calc(50% - 250px); float:left; } #pixelRight{ background:#999; width: calc(50% - 250px); float:right; } #bannerCenter,#pixelLeft,#pixelRight{ height: 400px; }

    You can use jQuery instead of using calc(50% - 250px); to make it compatible for older browsers.

    $(document).ready(function() {
        $(window).on('resize', function() {
             $('#pixelLeft, #pixelRight').css('width',($('body').width()-$('#bannerCenter').width())/2);
        }).trigger('resize');      
    });
    

    Update: June 2018

    Added flexbox solution for same problem.

    *{
        margin:0;
        padding:0;
    }
    .wrap {
      display: flex;
    }
    #pixelLeft, #pixelRight{
      display: flex;
      flex:1;
    }
    #bannerCenter{
        background:#ffffd;
        min-width: 500px;
        display: flex;
        flex: 1;
    }
    #pixelLeft{
        background:#999;
    }
    #pixelRight{
        background:#999;
    }
    #bannerCenter,#pixelLeft,#pixelRight{
        height: 400px;
    }
     
     

提交回复
热议问题