【问题标题】:Two divs side-by-side, 1st is fluid on the right, 2nd is fixed-width on the left两个 div 并排,第一个在右边是流动的,第二个在左边是固定宽度的
【发布时间】:2014-01-05 17:10:59
【问题描述】:

我目前有this situation - 两个 div,第一个固定在左侧,第二个在右侧流动。我需要切换两个 div 的 HTML 位置,但保持网页外观不变。

所以,

<div id="fixed"></div>
<div id="fluid"></div>

需要成为:

<div id="fluid"></div>
<div id="fixed"></div>

但是网页显示的时候,fluid div需要在右边,fixed在左边。我想不通。有没有办法做到这一点?

【问题讨论】:

    标签: css fluid-layout


    【解决方案1】:

    有多种方法可以做到这一点。最好将两个 div 都放在一个容器中,即使设置为 width: 100%

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <style media="all">
    .container {position: relative;}
    #fixed
    {
      width: 300px;
      height: 100px;
      background: #111;
      position: absolute;
      top: 0; left: 0;
    }
    
    #fluid
    {
      height: 100px;
      background: #555;
      margin-left: 300px;
    }
    
    </style>
    </head>
    <body>
    <div class="container">
        <div id="fluid"></div>
        <div id="fixed"></div>
    </div>
    
    </body>
    </html>
    

    一个现代的选择是使用 flexbox,但它还没有得到可靠的支持。

    【讨论】:

    【解决方案2】:

    float: right 添加到#fixed-div。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多