CSS Layout - Dynamic width DIV

前端 未结 4 976
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 03:43

I have a pretty common layout issue that I have traditionally used a table to solve, but would like some advice on getting it done with CSS. I have 3 images that makeup a \'

相关标签:
4条回答
  • 2020-12-31 04:04

    making a dynamycal width with mobile devices support

    http://www.codeography.com/2011/06/14/dynamic-fixed-width-layout-with-css.html

    0 讨论(0)
  • 2020-12-31 04:06

    This will do what you want. Fixed sides with 50px-width, and the content fills the remaining area.

    <div style="width:100%;">
        <div style="width: 50px; float: left;">Left Side</div>
        <div style="width: 50px; float: right;">Right Side</div>
        <div style="margin-left: 50px; margin-right: 50px;">Content Goes Here</div>
    </div>
    
    0 讨论(0)
  • try

    <div style="width:100%;">
        <div style="width:50px; float: left;"><img src="myleftimage" /></div>
        <div style="width:50px; float: right;"><img src="myrightimage" /></div>
        <div style="display:block; margin-left:auto; margin-right: auto;">Content Goes Here</div>
    </div>
    

    or

    <div style="width:100%; border:2px solid #dadada;">
        <div style="width:50px; float: left;"><img src="myleftimage" /></div>
        <div style="width:50px; float: right;"><img src="myrightimage" /></div>
        <div style="display:block; margin-left:auto; margin-right: auto;">Content Goes Here</div>
    <div style="clear:both"></div>    
    </div>
    
    0 讨论(0)
  • 2020-12-31 04:15

    Or, if you know the width of the two "side" images and don't want to deal with floats:

    <div class="container">
        <div class="left-panel"><img src="myleftimage" /></div>
        <div class="center-panel">Content goes here...</div>
        <div class="right-panel"><img src="myrightimage" /></div>
    </div>
    

    CSS:

    .container {
        position:relative;
        padding-left:50px;
        padding-right:50px;
    }
    
    .container .left-panel {
        width: 50px;
        position:absolute;
        left:0px;
        top:0px;
    }
    
    .container .right-panel {
        width: 50px;
        position:absolute;
        right:0px;
        top:0px;
    }
    
    .container .center-panel {
        background: url('mymiddleimage');
    }
    

    Notes:

    Position:relative on the parent div is used to make absolutely positioned children position themselves relative to that node.

    0 讨论(0)
提交回复
热议问题