父级中的两个div(左,右),宽度固定的右,左填充可用空间,都在同一行中。(无相对/绝对位置)

testCoder

我遇到了棘手的问题,我需要在一行中放置两个div(leftright),right必须具有固定的宽度,但是left必须填充可用空间,换句话说:left div必须具有100%-X像素,right div应该为X像素。

要点:没有位置相对/绝对hack。

有什么办法可以达到这个结果。我已经尝试了很多方法,但是没有运气。

这是jsfiddle

标记

<html>
<head>
    <title></title>
</head>
<body>
    <style>
        .container {
            /* container don't matter */
            width: 500px;
            background-color: bisque;
            height: 50px;
        }

            .container .left {
               /* display: inline-block; */ 
                margin-right: 50px;
                background-color: burlywood;
                height: 50px;
            }

            .container .right {
                float: right;
                background-color: chartreuse;
                width: 50px;
                height: 50px;
            }
    </style>
    <div class="container">
        <div class="left">
            fill free space (100% - right)
        </div>
        <div class="right">
            fixed width
        </div>
    </div>
</body>
</html>
匿名的

您可以这样做:

JSFiddle-演示

CSS:

.container {
    width: 500px;
    background-color: bisque;
    height: 50px;
    display: table;
}
.container .left {
    background-color: burlywood;
    height: 50px;
    display: table-cell;
    width: 100%;
}
.container .right {
    background-color: chartreuse;
    width: 50px;
    height: 50px;
    display: inline-block;
    vertical-align: text-top;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档