代码之家  ›  专栏  ›  技术社区  ›  Advanced SEO

左右对齐4个div?[副本]

  •  -3
  • Advanced SEO  · 技术社区  · 9 年前

    我有四个跳水,第一个应该在左边,第二个应该在右边,第三个在左边,第一个在右边,而第四个在右边。

    如何使用第四个div固定垂直对齐?

    此外,我还创建了打印屏幕图像,现在如何,应该如何,希望它会有所帮助?

    http://s27.postimg.org/k3g2tvxwj/4_divs.png

    <!DOCTYPE html>
    <html lang="en-US">
    
    <head>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>test</title>
      <style>
      .container {
        width: 90%;
        margin 0 auto;
        border: 2px solid #000;
        margin: 5px;
      }
      .align-left {
        width: 60%;
        float: left;
        border: 2px solid #000;
        margin: 5px;
      }
      .align-right {
        width: 35%;
        float: right;
        border: 2px solid #000;
        margin: 5px;
      }
    
      </style>
    </head>
    
    <body>
    
      <div>
        <header>
          <header>
            <div class="container">
    
              <div class="align-left">
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
              </div>
    
              <div class="align-right">
                2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
              </div>
    
              <div class="align-left">
                3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
              </div>
    
    
              <div class="align-right" style="color:red">
                4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
              </div>
    
    
            </div>
    
      </div>
      <!-- #page -->
    </body>
    
    </html>
    
    3 回复  |  直到 9 年前
        1
  •  2
  •   Community CDub    7 年前

    我找到了!( Hat tip to this post )它基本上说,从右边的容器中取出浮子,它们将占据两个浮动的左边div周围的可用空间:

    * {
    box-sizing: border-box;
    }
    .container{
    width:100%;
    outline: 2px solid #000;
    padding: 5px;
    }
    
    .half {
      width: 50%;
      }
    
    .align-left{
    width:60%;
      float: left;
    display: inline-block;
    outline: 2px solid #000;
    padding: 5px;
    }
    
    .align-right{
    width:30%;
    
    display: inline-block;
    outline: 2px solid #000;
    padding: 5px;
    }
    <!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>test</title>
    
    </head>
    <body>
    
    <div>
    <header>
    <header>
            <div class="conainer">
    
                <div class="align-left">
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1           
                </div>
    
                <div class="align-right">
                2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 
                </div>
    
                <div class="align-left">
                3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 
                 </div>
    
    
                 <div class="align-right" style="color:red">
                4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 
                 </div>
    
    
            </div>
    
    </div><!-- #page -->
    </body>
    </html>
        2
  •  1
  •   Dilip Nayak    9 年前

    在第四个div上使用css样式

    position:relative;
    top: -100px; // change according to your requirement
    
        3
  •  0
  •   Adnan Akram    9 年前

    要实现这一点,最好使用砌体jQuery插件 http://isotope.metafizzy.co