CSS三列布局

发布时间:2020-06-20 11:59:56 作者:jjjyyy66
来源:网络 阅读:287

两侧定宽中间自适应布局

思路一:  float

【1】float + margin + calc

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left,.right{float: left;width: 100px;}.center{float: left; width:calc(100% - 240px);margin: 0 20px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>    
    <div class="right"  >
        <p>right</p>
    </div>        </div>

CSS三列布局

【2】float + margin + (fix)

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left,.right{position: relative;float: left;width: 100px;}.centerWrap{float: left; width:100%; margin: 0 -100px;}.center{margin: 0 120px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>            
    <div class="centerWrap" >
        <div class="center" >
            <p>center</p>
            <p>center</p>
        </div>        
    </div>
    <div class="right"  >
        <p>right</p>
    </div>            </div>

CSS三列布局

 

思路二: inline-block

【1】inline-block + margin + calc

CSS三列布局

<style>p{margin: 0;}.parent{font-size: 0;}.left,.right,.center{display:inline-block; vertical-align: top;font-size: 16px;}.left,.right{width: 100px;}.center{width: calc(100% - 240px); margin: 0 20px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>            
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>        
    <div class="right"  >
        <p>right</p>
    </div>            </div>

CSS三列布局

【2】inline-block + margin + (fix)

CSS三列布局

<style>p{margin: 0;}.parent{font-size: 0;}.left,.right,.centerWrap{display:inline-block; vertical-align: top;font-size: 16px;}.left,.right{width: 100px;position:relative;}.centerWrap{width: 100%; margin: 0 -100px;}.center{margin: 0 120px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="centerWrap" >
        <div class="center" >
            <p>center</p>
            <p>center</p>
        </div>        
    </div>        
    <div class="right"  >
        <p>right</p>
    </div>            </div>

CSS三列布局

 

思路三: table

CSS三列布局

<style>p{margin: 0;}.parent{display: table; width: 100%;table-layout: fixed;}.left,.right,.centerWrap{display:table-cell;}.left,.right{width: 100px;}.center{margin: 0 20px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="centerWrap" >
        <div class="center" >
            <p>center</p>
            <p>center</p>
        </div>        
    </div>        
    <div class="right"  >
        <p>right</p>
    </div>            </div>

CSS三列布局

 

思路四: absolute

CSS三列布局

<style>p{margin: 0;}.parent{position: relative;height:40px;}.left,.right,.center{position: absolute;}.left{left: 0;width:100px;}.right{right: 0;width: 100px;}.center{left: 120px; right: 120px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>                
    <div class="right"  >
        <p>right</p>
    </div>            </div>

CSS三列布局

 

思路五: flex

CSS三列布局

<style>p{margin: 0;}.parent{display: flex;}.left,.right{width: 100px;}.center{flex: 1; margin: 0 20px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>                
    <div class="right"  >
        <p>right</p>
    </div>            </div>

CSS三列布局

 

两列定宽一侧自适应布局

  这种布局与单列定宽单列自适应布局非常相似

思路一: float

【1】float + margin

  缺点是IE6-浏览器的3px的bug,以及当自适应列中有元素清除浮动时,会使该元素不与左侧浮动元素同行,从而出现文字下沉现象

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left,.center{float: left;width: 100px;margin-right: 20px;}.right{margin-left: 240px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
    </div>                
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>            </div>

CSS三列布局

【2】float + margin + calc

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left,.center{float: left;width: 100px;margin-right: 20px;}.right{float: left; width: calc(100% - 240px);}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
    </div>                
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>            </div>

CSS三列布局

【3】float + margin + (fix)

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left,.center{position: relative; float: left;width: 100px;margin-right: 20px;}.rightWrap{float: left; width: 100%; margin-left: -240px;}.right{margin-left:240px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
    </div>        
    <div class="rightWrap">
        <div class="right"  >
            <p>right</p>
            <p>right</p>
        </div>            
    </div>            </div>

CSS三列布局

 【4】float + overflow

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left,.center{position: relative; float: left;width: 100px;margin-right: 20px;}.right{overflow: hidden;zoom:1;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
    </div>        
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                        </div>

CSS三列布局

 

思路二: inline-block

【1】inline-block + margin + calc

CSS三列布局

<style>p{margin: 0;}.parent{font-size: 0;}.left,.right,.center{display:inline-block; vertical-align: top;font-size: 16px;}.left,.center{width: 100px;margin-right:20px;}.right{width: calc(100% - 240px);}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
    </div>        
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                        </div>

CSS三列布局

【2】inline-block + margin + (fix)

CSS三列布局

<style>p{margin: 0;}.parent{font-size: 0;}.left,.rightWrap,.center{display:inline-block; vertical-align: top;font-size: 16px;}.left,.center{position: relative;width: 100px;margin-right:20px;}.rightWrap{width:100%; margin-left: -240px;}.right{margin-left: 240px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>    
    <div class="center" >
        <p>center</p>
    </div>        
    <div class="rightWrap" >
        <div class="right"  >
            <p>right</p>
            <p>right</p>
        </div>        
    </div>            </div>

CSS三列布局

 

思路三: table

CSS三列布局

<style>p{margin: 0;}.parent{display: table; width: 100%;table-layout: fixed;}.leftWrap,.centerWrap,.right{display:table-cell;}.leftWrap,.centerWrap{width: 120px;}.left,.center{margin-right: 20px;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="leftWrap">
        <div class="left" >
            <p>left</p>
        </div>        
    </div>
    <div class="centerWrap">
        <div class="center" >
            <p>center</p>
        </div>        
    </div>
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>            </div>

CSS三列布局

 

思路四: absolute

CSS三列布局

<style>p{margin: 0;}.parent{position: relative;width:100%;height:40px;}.left{position: absolute;left:0;width:100px;}.center{position: absolute;left:120px;width: 100px;}.right{position: absolute;left:240px; right:0;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>        
    <div class="center" >
        <p>center</p>
    </div>        
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>            </div>

CSS三列布局

 

思路五: flex

CSS三列布局

<style>p{margin: 0;}.parent{display: flex;}.left,.center{width:100px;margin-right:20px;}.right{flex:1;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>        
    <div class="center" >
        <p>center</p>
    </div>        
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>            </div>

CSS三列布局

 

中间定宽两侧自适应布局

思路一: float

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left{float: left;margin-right: 20px;}.center{float: left;width: 100px;margin-right: 20px;}.right{overflow: hidden;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
        <p>left</p>
    </div>        
    <div class="center" >
        <p>center</p>
    </div>    
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

思路二: table

CSS三列布局

<style>p{margin: 0;}.parent{display: table; width: 100%;}.leftWrap{display: table-cell; width: 0.1%;}.centerWrap{display: table-cell;width: 120px;}.left,.center{margin-right: 20px;}.right{display:table-cell;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="leftWrap">
        <div class="left" >
            <p>left</p>
            <p>left</p>
        </div>            
    </div>
    <div class="centerWrap">
        <div class="center" >
            <p>center</p>
        </div>            
    </div>
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

思路三: flex

CSS三列布局

<style>p{margin: 0;}.parent{display: flex;}.left{margin-right: 20px;}.center{width: 100px;margin-right: 20px;}.right{flex: 1;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
        <p>left</p>
    </div>            
    <div class="center" >
        <p>center</p>
    </div>            
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

一侧定宽两列自适应布局

思路一: float

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left{float: left;width: 100px;margin-right: 20px;}.center{float: left;margin-right: 20px;}.right{overflow: hidden;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>            
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>            
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

思路二: table

CSS三列布局

<style>p{margin: 0;}.parent{display: table; width: 100%;}.leftWrap{display: table-cell; width: 120px;}.centerWrap{display: table-cell;width: 0.1%;}.left,.center{margin-right: 20px;}.right{display:table-cell;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="leftWrap">
        <div class="left" >
            <p>left</p>
        </div>            
    </div>
    <div class="centerWrap">
        <div class="center" >
            <p>center</p>
            <p>center</p>
        </div>            
    </div>
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

思路三: flex

CSS三列布局

<style>p{margin: 0;}.parent{display: flex;}.left{width: 100px;margin-right: 20px;}.center{margin-right: 20px;}.right{flex: 1;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
    </div>            
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>            
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

三列自适应布局

思路一: float

CSS三列布局

<style>p{margin: 0;}.parent{overflow: hidden;}.left,.center{float: left;margin-right: 20px;}.right{overflow: hidden;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
        <p>left</p>
    </div>            
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>            
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

思路二: table

CSS三列布局

<style>p{margin: 0;}.parent{display: table; width: 100%;}.leftWrap,.centerWrap{display: table-cell;width: 0.1%;}.left,.center{margin-right: 20px;}.right{display:table-cell;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="leftWrap">
        <div class="left" >
            <p>left</p>
            <p>left</p>
        </div>            
    </div>
    <div class="centerWrap">
        <div class="center" >
            <p>center</p>
            <p>center</p>
        </div>            
    </div>
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 

思路三: flex

CSS三列布局

<style>p{margin: 0;}.parent{display: flex;}.left,.center{margin-right: 20px;}.right{flex: 1;}</style>

CSS三列布局

CSS三列布局

<div class="parent" >
    <div class="left" >
        <p>left</p>
        <p>left</p>
    </div>            
    <div class="center" >
        <p>center</p>
        <p>center</p>
    </div>            
    <div class="right"  >
        <p>right</p>
        <p>right</p>
    </div>                    </div>

CSS三列布局

 


推荐阅读:
  1. css Flexbox布局用法
  2. 什么是css grid布局

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

center hidden parent

上一篇:IO流-设置输出字符编码格式

下一篇:询表空间是否查自动扩展   tablespace /   auto

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》