【问题标题】:How to float three divs right to left?如何从右到左浮动三个div?
【发布时间】:2015-02-07 17:45:07
【问题描述】:

我想我了解基本的左右浮动,但我无法弄清楚这个特殊的三栏布局。我什至不确定我想要什么是可能的。我想创建一个包含三个

列的单行,如下所示:
  1. 最右边的
    触及容器的右边缘, 包含 nowrap 文本,并且根据需要尽可能宽。
  2. 中心
    紧邻最右侧的左侧
    ,包含一个 ,根据需要设置宽度。
  3. 最左边的
    触及容器的左边缘, 包含自动换行的文本,并使用 20% 的最小宽度,但 动态拉伸以使用任何可用的剩余宽度 在容器中。
  4. 当(且仅当) 三列的宽度大于 容器。我不希望这些
    中的任何一个向下移动到 下一行。

    我在使用 #3 和 #4 时遇到问题。这可能吗?我猜我需要最左边的列实际上是两个

    (一个直接在另一个之上),一个空的
    上面/下面有 20% 的宽度,另一个包装的文本
    宽度未指定,但我不知道该怎么做。


    谢谢,
    汤姆三世

    【问题讨论】:

标签: html css


【解决方案1】:
        <style>
            #main{
                position: fixed;
                top: 0; 
                left: 0;
                width: 100%;
                height: 100%;
            }
            #left{
                float: left;
                max-width: 32%;
                width: auto;
                margin-right: 3px;
                background-color: red;
            }
            #center{
                float: left;
                max-width: 32%;
                width: auto;
                margin-right: 3px;
                margin-left: 3px;
                background-color: green;
            }
            #right{
                float: right;
                max-width: 32%;
                width: auto;
                min-width: 20%;
                background-color: blue;
            }
        </style>
        <div id="main">
            This is the main div!
                <div id="left">
                    Hello From The Left!
                </div>
                <div id="center">
                    Hello From The Center!
                </div>
                <div id="right">
                    Hello From The Center!
                </div>
        </div>

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签