如果有 space,则在左浮动和右浮动 Div 之间放置一个 Div,如果 space 不够,则将其放置在它们下方

Placing a Div between a Left and Right floated Div if there is space, placing it below them if there is not enough space

我正在为一个网站开发导航栏,就像您的普通导航栏一样,它有一个徽标(浮动:左侧)、指向其他页面的链接以及最后的帐户设置(浮动:右侧),所有侧面旁边。当 window 调整大小时,我希望能够在不水平滚动的情况下仍然显示导航栏的所有元素。我想通过将所有指向页面的链接放在徽标下方(并且仍然在右上角有帐户设置)来做到这一点。

在全屏模式下,导航栏工作得很好(足够简单)。当 window 调整大小时,一切都变得混乱(最后的 div 结束于 window)。

The two top images are illustrations of what im working towards, and the third one down is my current issue.

我在 css 方面有一些经验,但了解如何解决这个问题(或查找如何解决这个问题)超出了我的能力范围。我真的很感激一些帮助:)

附加的代码片段,是使用 "CSS grid" 和媒体查询的基础。 CSS 中有一些重复项,可以花更多时间进行改进,从而最大限度地减少代码。它让您了解这些布局是如何构建的。

 @media only screen and (max-width: 600px) {

.wrapper {
  display: grid;
  grid-template-columns:
  1fr
  ;
  grid-template-rows:
  100px
  100px
  100px
  ;
  grid-template-areas:
  "header-1"
  "header-2"
  "content"
  ;
}

.header-1 {
  grid-area: header-1;
  background-color: grey;
}

.header-2 {
  grid-area: header-2;
  background-color: grey;
}

.content {
  grid-area: content;
  background-color: lightgrey;
}

.header-1 {
  display: grid;
  grid-template-columns:
  1fr
  1fr
  1fr
  ;
  grid-template-rows:
  100px
  ;
  grid-template-areas:
  "box-1 box-2 box-3"
  ;
}


.box-1 {
  grid-area: box-1;
  background-color: magenta;
  margin: 10px;
}

.box-2 {
  grid-area: box-2;
  background-color: cyan;
  margin: 10px;
}

.box-3 {
  grid-area: box-3;
  background-color: green;
  margin: 10px;
}

}

 @media only screen and (min-width: 600px) {

   .wrapper {
     display: grid;
     grid-template-columns:
     1fr
     ;
     grid-template-rows:
     100px
     100px
     100px
     ;
     grid-template-areas:
     "header-1"
     "header-2"
     "content"
     ;
   }

   .header-1 {
     grid-area: header-1;
     background-color: grey;
   }

   .header-2 {
     grid-area: header-2;
     background-color: grey;
   }

   .content {
     grid-area: content;
     background-color: lightgrey;
   }

   .header-1 {
     display: grid;
     grid-template-columns:
     1fr
     1fr
     1fr
     ;
     grid-template-rows:
     100px
     ;
     grid-template-areas:
     "box-1 . box-3"
     ;
   }

   .header-2 {
     display: grid;
     grid-template-columns:
     1fr
     1fr
     1fr
     ;
     grid-template-rows:
     100px
     ;
     grid-template-areas:
     "box-2 box-2 box-2"
     ;
   }


   .box-1 {
     grid-area: box-1;
     background-color: magenta;
     margin: 10px;
   }

   .box-2 {
     grid-area: box-2;
     background-color: cyan;
   }

   .box-3 {
     grid-area: box-3;
     background-color: green;
     margin: 10px;
   }

 }
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="index.css">
  <title>Document</title>
</head>

<body>

<div class="wrapper">

    <div class="header-1">
        <div class="box-1"></div>
        <div class="box-2"></div>
        <div class="box-3"></div>
    </div>

    <div class="header-2">
      <div class="box-1"></div>
      <div class="box-2"></div>
      <div class="box-3"></div>
    </div>

    <div class="content"></div>

</div>



</body>
</html>