-1

I have two flex items in a container wrapped in a column, and there it is a big space between the the two boxes, I tried to use align-items: flex-start; or align-self: flex-start; but does not work.

please look at the code snippet.

thank you.

.wrapper {
  display: flex;
  }
.content {
  width: 300px;
  height: 400px;
  background: green;
  }
.sidebar {
    display: flex;
    /* flex-basis: 100px; */
    flex-wrap: wrap;
    align-items: flex-start;
    max-width: 100px;
}
.sidebar > div {
    background: blue;
    width: 100px;
    height: 50px;
    align-self: flex-start;
}
<div class = "wrapper">

  <div class="sidebar">

    <div></div>
    <div></div>

  </div>

  <div class = "content">

  </div>

</div>
Botond Vajna
  • 1,295
  • 1
  • 10
  • 22

3 Answers3

2

You could simply use flex-direction:column; to get them one below the other.

If this is what you are looking for :) Also for your information, flex-basis is the property of flex-items and not of flex-container.

.sidebar {
    display: flex;
       height: 400px;
       flex-direction:column;
       max-width: 280px;
}
.sidebar > div {
    background: blue;
    width: 280px;
    height: 50px;
    margin-bottom:0.5rem;
}
<div class="sidebar">

    <div></div>
    <div></div>

</div>
Imran Rafiq Rather
  • 7,677
  • 1
  • 16
  • 35
1

You need to add flex-direction: column; to the .sidebar

.sidebar {
    display: flex;
    /* flex-basis: 280px; */
    flex-wrap: wrap;
    align-items: flex-start;
    height: 400px;
    max-width: 280px;
    flex-direction: column;
}
.sidebar > div {
    background: blue;
    width: 280px;
    height: 50px;
    margin-top: 1px; /* Demo purposes */
}
<div class="sidebar">

<div></div>
<div></div>

</div>
TechySharnav
  • 4,869
  • 2
  • 11
  • 29
-1

no need to wrap your flexbox of .sidebar just simply comment it out. and add flex-direction: column;

.wrapper {
  display: flex;
  }
.content {
  width: 300px;
  height: 400px;
  background: green;
  }
.sidebar {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
    /* flex-basis: 100px; */
    /* flex-wrap: wrap; */
    align-items: flex-start;
    max-width: 100px;
}
.sidebar > div {
    background: blue;
    width: 100px;
    height: 50px;
    align-self: flex-start;
}
<div class = "wrapper">

      <div class="sidebar">

        <div></div>
        <div></div>

      </div>

      <div class = "content">

      </div>

    </div>
Anonymous Coder
  • 556
  • 2
  • 16