子元素高度与父元素一致

 

<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>子元素高度与父元素一致</title>
    <style>

        .parent{
            position: relative;
            background: #f89;

            width: 800px;
            color: #fff;
            font-family: "Microsoft Yahei";
            text-align: center;
        }
        .left {
            min-height: 700px;
            width: 600px;

        }
        .right {
            width: 200px;
            position: absolute;
            top: 0;
            right: 0;
            height: 100%;

            overflow: auto;

            background: #ccc;

        }
        .right-inner {
            background: limegreen;
            height: 1024px;
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="left">
            左侧 left 不定高,parent的高度随着左侧left 的高度变化而变化,右侧也跟着变
        </div>
        <div class="right">
            <div class="right-inner">right的子元素,高度为1024px,会撑破容器,给.right加上 overflow:auto 就防止溢出了</div>
        </div>
    </div>
</body>
</html>

 

参考资料:http://blog.csdn.net/ann295258232/article/details/52680438

 

posted @ 2018-03-21 15:18  linyongqin  阅读(606)  评论(0编辑  收藏  举报