Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the div order if it wraps/overflows, without media queries

Tags:

html

css

flexbox

Here is my problem. I have a navbar whose menus/links are located in the center. on the left is the logo, on the right are cta buttons and icons

If it overflows/wrap, the center column should put it on the next line at full width and the left and right column stays on top as 2 columns.

Given this sample code:

* {
  box-sizing: border-box;
}
body, html {
  margin: 0;
  padding: 0;
}
.content {
  display: flex;
  flex-wrap: wrap;
}

.a, .b, .c{
  border: 1px solid black;
  flex: 1;
  padding: 10px;
}


.b, .c {
 flex-wrap: wrap-reverse;
}
<div class="content">
  <div class="a">LogoAndStuff</div>
    <div class="b">Link1,Link2,Link3,Link4</div>
    <div class="c">Buttons,Icons</div>
</div>

Fiddle: https://jsfiddle.net/3erodmv7/3/

Menu items/links has dynamic width so I rely on overflow/wrapping instead of fixed width and media queries.

Not overflow:

--------------------------------------
| Logo | Link1,Link2,Link3 | Buttons |
--------------------------------------

overflow:

------------------------------------
| Logo            |        Buttons |
------------------------------------
| Link1,Link2,Link3                |
------------------------------------
like image 906
D.R.Bendanillo Avatar asked Aug 20 '19 23:08

D.R.Bendanillo


1 Answers

With float you can approximate this but you will have less flexibility to control width like you are doing with the flex property

* {
 box-sizing:border-box;
}
body,
html {
  margin: 0;
  padding: 0;
}

.a,
.c {
  border: 1px solid black;
  padding: 10px;
  width:33%;
  min-width:110px;
}
.a {
 float:left;
}
.c {
 float:right;
}
.b {
  border: 1px solid black;
}

.b span{
  display:inline-block;
  padding: 10px;
}
<div class="content">
  <div class="a">LogoAndStuff</div>
  <div class="c">Buttons,Icons</div>
  <div class="b"><span>Link1,Link2,Link3,Link4</span></div>
</div>
like image 164
Temani Afif Avatar answered Oct 16 '22 23:10

Temani Afif