2.布局解决方案- 等分<7>

第一种方式 float +box-sizing

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        body,p{
            padding: 0;
            margin: 0;
        }
        .column{
            width: 25%;
            float: left;
            padding-left: 10px;
            box-sizing: border-box;
        }
        .column p{
            background: red;
        }
    </style>
</head>
<body>
<div class="parent">
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
</div>
</body>
</html>

但是具有耦合性去掉一列的话还要修改样式这是它的不足之处

第二种方式 display:table

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        body,p{
            padding: 0;
            margin: 0;
        }
        .parent{
            display: table;
            width: 100%;
        }
        .column{
             display: table-cell;
             padding-left: 10px;
        }
        .column p{
            background: greenyellow;
        }
    </style>
</head>
<body>
<div class="parent">
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
</div>
</body>
</html>

第三种方式 flex

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        body,p{
            padding: 0;
            margin: 0;
        }
        .parent{
            display: flex;
        }
        .column{
            background: yellowgreen;
            flex: 1;
            margin-left: 10px;
        }
        .column p{
            background: red;
        }
    </style>
</head>
<body>
<div class="parent">
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
    <div class="column"><p>内容1</p></div>
</div>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,816评论 1 92
  • 移动开发基本知识点 一.使用rem作为单位 html { font-size: 100px; } @media(m...
    横冲直撞666阅读 3,527评论 0 6
  • H5移动端知识点总结 阅读目录 移动开发基本知识点 calc基本用法 box-sizing的理解及使用 理解dis...
    Mx勇阅读 4,644评论 0 26
  • 2015年3月1日星期日 真是无语,自己也是过糊涂了 不晓得今年二月份只有28天! 所以,我整整多算了三天! 天呐...
    蒙古海军上将阅读 154评论 0 1
  • 你说让我们走着散吧 总归是要分离的 何必自寻苦恼 我无从辩解 也无法否认 只能是微笑着 温雅的 支撑着残破的躯壳 ...
    南心北木mua阅读 342评论 0 3