代码之家  ›  专栏  ›  技术社区  ›  Haox

如何用HTML和CSS分隔两个flex块?

  •  1
  • Haox  · 技术社区  · 7 年前

    我的代码不起作用,我不明白为什么。。。

    我用的是flex-box,我是新来的,如果解决方法简单的话,我很抱歉。

    谢谢您

    @charset "UTF-8";
    /* CSS Document */
    body {
      margin: 0;
      font-size: 28px;
      background-color: #747474;
    }
    
    
    /* Style the navbar */
    
    
    #navbar {
      overflow: hidden;
      background: rgba(191, 191, 191 ,0.5);
      display: flex;
      justify-content: flex-end;
    
    }
    
    .test:nth-child(1){
      order: 1;
      align-items: flex-start;
    }
    .test:nth-child(2){
      order: 4;
    }
    .test:nth-child(3){
      order: 3;
    }
    .test:nth-child(4){
      order: 2;
    }
    .test:nth-child(5){
      order: 5;
    }
    <!DOCTYPE html>
    <html>
    
        <link rel="stylesheet" href="CSS/style2.css" />
        <link rel="shortcut icon" href="IMAGES/PNG/favicon.png" />
    
        <head>
            <meta charset="utf-8" />
            <title>Electrophotonique Ingenierie</title>
        </head>
    
    
        <body>
    
            <div class="test2">
                <div id="navbar">
                  <div class="test"> <a href= "index2.html">Electrophotonique Ing.</a></div>
                  <div class="test"> <a class="active" href="javascript:void(0)">Blog</a></div>
                  <div class="test"> <a href="blog">Contact</a></div>
                  <div class="test"> <a href="blog">L'électrophotonique</a></div>
                  <div class="test"> <a href="blog">Qui sommes nous?</a></div>
    
    
                </div>
    
        <div class="content">
    
        </div>
    
    
    <script type="text/javascript" src="JS/sticky_navbar.js"></script>
    
    
    </body>
    </html>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   enxaneta    7 年前

    我不太明白你的问题。这就是你想要达到的目标:

    body {
      margin: 0;
      background-color: #747474;
      font-size:12px;
    }
    
    
    /* Style the navbar */
    
    
    #navbar {
      overflow: hidden;
      background: rgba(191, 191, 191 ,0.5);
      display: flex;
      justify-content: flex-end;
    
    }
    .test{padding:.5em 1em;}
    
    .test:nth-child(1){
      order: 1;
      margin:0 auto 0 0;
      
    }
    .test:nth-child(2){
      order: 4;
    }
    .test:nth-child(3){
      order: 3;
    }
    .test:nth-child(4){
      order: 2;
    }
    .test:nth-child(5){
      order: 5;
    }
    <div class="test2">
      <div id="navbar">
        <div class="test"> <a href="index2.html">Electrophotonique Ing.</a></div>
        <div class="test"> <a class="active" href="javascript:void(0)">Blog</a></div>
        <div class="test"> <a href="blog">Contact</a></div>
        <div class="test"> <a href="blog">L'électrophotonique</a></div>
        <div class="test"> <a href="blog">Qui sommes nous?</a></div>
    
      </div>
    
      <div class="content">
    
      </div>