css两列等高

#### css 表格布局
```
<html>

<head>
    <style>
        .compare {
            width: 100%;
            border: 1px solid black;
            height: 100px;
            margin-bottom: 10px;
        }
        
        .container {
            /* 显示为table的元素宽度不会扩展到100%,因此需要明确指定宽度 */
            display: table;
            width: 100%;
            border: 1px solid black;
            border-spacing: 1.5em .5em;
        }
        
        .main {
            display: table-cell;
            width: 70%;
            background-color: #fff;
            border-radius: .5em;
            border: 1px solid black;
        }
        
        .sidebar {
            display: table-cell;
            width: 30%;
            /* 外边距并不会作用于table-cell元素 */
            /* margin-left: 1.5em; */
            padding: 1.5em;
            /* border-spacing作用于单元格之间和表格的外边缘 */
            background-color: #fff;
            border-radius: .5em;
            border: 1px solid black;
        }
        
        .wrapper {
            margin: 0 -1.5em;
        }
    </style>
</head>

<body>
    <div class="compare"></div>
    <div class="wrapper">
        <div class="container">
            <div class="main">xxxxxxxxxxxxxxxxxxxxx</div>
            <div class="sidebar">yyyyyyyyyyyyyyyyy</div>
        </div>
    </div>

    <script>
    </script>
</body>

</html>
```
#### flex 布局
ie9 建议使用flex 布局
```
<html>

<head>
    <style>
        .compare {
            width: 100%;
            border: 1px solid black;
            height: 100px;
            margin-bottom: 10px;
        }
        
        .container {
            display: flex;
            border: 1px solid black;
        }
        
        .main {
            width: 70%;
            background-color: green;
            border-radius: 0.5em;
            border: 1px solid black;
        }
        
        .sidebar {
            display: table-cell;
            width: 30%;
            padding: 1.5em;
            margin-left: 1.5em;
            background-color: yellow;
            border-radius: .5em;
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <div class="compare"></div>
    <div class="container">
        <div class="main">xxxxxxxxxxxxxxxxxxxxx</div>
        <div class="sidebar">yyyyyyyyyyyyyyyyy</div>
    </div>

    <script>
    </script>
</body>

</html>


<!-- 除非别无选择,否则不要明确设置元素的高度。先寻找一个替代方案。设置高度一定会导致更复杂的情况。 -->
```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值