前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >等高布局

等高布局

作者头像
windseek
发布2018-06-15 18:02:22
4040
发布2018-06-15 18:02:22
举报
文章被收录于专栏:杨龙飞前端杨龙飞前端

1、使用margin负边距:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <style type="text/css">
    .parent{
      position:relative;
      overflow:hidden;
    }
    .left{
      background:red;
      left:0px;
    }
    .center{
      background:yellow;
    }
    .right{
      background:green;
    }
    .left,.center,.right{
      float:left;    
       padding-bottom: 500px;
      margin-bottom: -500px;
    }
    
  </style>
</head>
<body>
<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>
</body>
</html>

?2、使用table

代码语言:javascript
复制
<html>
<head>
<style type="text/css">
body,p{margin: 0;}
.parent{
    display: table;
    width: 100%;
    table-layout: fixed;
}
.left,.centerWrap,.right{
    display: table-cell;
}
.center{
    margin: 0 20px;
}
</style>
</head>
<body>
<div class="parent" style="background-color: lightgrey;">
    <div class="left" style="background-color: lightblue;">
        <p>left</p>
    </div>  
    <div class="centerWrap">
        <div class="center" style="background-color: pink;">
            <p>center</p>
            <p>center</p>
        </div>         
    </div> 
    <div class="right" style="background-color: lightgreen;">
        <p>right</p>
    </div>        
</div>
</body>
</html>

3、使用flex

代码语言:javascript
复制
<html>
<head>
<style>
body,p{margin: 0;}
.parent{
    display: flex;
}
.left,.center,.right{
    flex: 1;
}
.center{
    margin: 0 20px;
}
</style>
</head>
<body>
<div class="parent" style="background-color: lightgrey;">
    <div class="left" style="background-color: lightblue;">
        <p>left</p>
    </div>  
    <div class="center" style="background-color: pink;">
        <p>center</p>
        <p>center</p>
    </div>          
    <div class="right" style="background-color: lightgreen;">
        <p>right</p>
    </div>        
</div>
</body>
</html>

?4、使用grid

代码语言:javascript
复制
<html>
<head>
<style>
body,p{margin: 0;}
.parent{
    display: grid;
    grid-auto-flow: column;
    grid-gap:20px;
}
</style>
</head>
<body>
<div class="parent" style="background-color: lightgrey;">
    <div class="left" style="background-color: lightblue;">
        <p>left</p>
    </div>  
    <div class="center" style="background-color: pink;">
        <p>center</p>
        <p>center</p>
    </div>          
    <div class="right" style="background-color: lightgreen;">
        <p>right</p>
    </div>        
</div>
</body>
</html>

?推荐使用table和margin负边距,简单好用,不存在兼容性

gird,flex也很简单,但是兼容性不太好

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-03-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com