如何将2个flex块与HTML和CSS分开?

时间:2018-09-05 20:24:05

标签: javascript html css css3 flexbox

我正在寻找一个水平工具栏,右边有4个项目,左边只有一个。

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

我想要“电子工程”。在左侧,在右侧,但我的代码不起作用...

我用了弹性包装盒,我是新来的,如果解决方案简单,抱歉。

你能帮我吗?

谢谢

@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 个答案:

答案 0 :(得分:2)

我不太确定我是否理解您的问题。这是您想要实现的目标吗?

<amp-list>
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;
}