0

I want to accomplish something like the image, but without the third element, having one element fixed on the left and another in the center.

enter image description here

Is there an easier way without flexbox?

<div style="display: flex; justify-content: space-between">
  <button>Left Header</button>
  <button>middle</button>
</div>
StudioWorks
  • 483
  • 1
  • 6
  • 25

4 Answers4

1

Im sure there is a better way, but how about just hiding last column?

.container {
  display: flex;
  justify-content: space-between;
}

.item {
  /* no important; just to visualize*/
  width: 50px;
  height: 50px;
  background-color: blue;
  border: 1px solid;
}

.item.last { /* :last-child doesn't work */
  visibility: hidden;
  background-color: red;
}
<div class="container">
  <div class="item">A</div>
  <div class="item">B</div>
  <div class="item last">C</div>
<div>
ulou
  • 5,542
  • 5
  • 37
  • 47
1

You can use postion for first div and margin for the second div, like this

.container {
  postion: relative;
}

.item {
  width: 50px;
  height: 50px;
  background-color: teal;
  border: 1px solid grey;
}

.item.one {
  position: absolute;
}

.item.two {
  margin: auto
}
<div class="container">
  <div class="item one">A</div>
  <div class="item two">B</div>
<div>
1

you can follow this code


<div style="display: flex; justify-content: space-between">
  <button>Left Header</button>
  <button style="margin-right: auto; margin-left: auto">middle</button>
</div>

mohammad13
  • 453
  • 3
  • 17
0

You can just use flexbox "self-align".

Just check it here.

  • 1
    This only works if `flex-direction` is set to `column`, which results in the items not being displayed in the same row. – tobimori Apr 26 '21 at 17:14