码迷,mamicode.com
首页 > Web开发 > 详细

css将两个元素水平对齐,兼容IE8

时间:2019-11-12 20:02:02      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:splay   cell   水平   height   com   border   rap   显示   http   

css实现元素水平对齐

css实现水平对齐,如图
技术图片

有人会说css实现这种水平对齐要兼容ie8还不简单吗?使用float: left,或者display: inline-block,不就可以了吗?是的,最常用的最简单方式就是上面这两种,但还有一种方式也可以实现,那就是使用display: table-cell;

示例代码

<style type="text/css">
    *{
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    .container{
        width: 1000px;
        height: 1000px;
        margin: 100px;
        background-color: #f60;
    }
    .left{
       /*关键点在于将两个元素设置为display:table-cell*/
        display: table-cell;
        vertical-align: top;
        width: 20%;
        min-width: 200px;
        height: 400px;
        background-color: #ccc;
    }
    .right{
        display: table-cell;
        vertical-align: top;
        /*即使宽度设为2000px,元素的内容还是可以正常显示*/
        width: 2000px;
        height: 600px;
        background-color: #f10;
    }
</style>
<div class="container">
    <div class="left">left</div>
    <div class="right">right</div>
</div>

css将两个元素水平对齐,兼容IE8

标签:splay   cell   水平   height   com   border   rap   显示   http   

原文地址:https://www.cnblogs.com/jlfw/p/11844383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!