0

I need some help to align the div number 3 to always be on the bottom of the container. The right side container has more content but grid makes both the same size. Left container uses flex. Since flex-direction is column, I tried to justify-self: flex-end for div number 3 but it's not working, but align-self: flex-end works, the other divs are centered while 3 is on the right. How can I fix this?

body{
    display: grid;
    grid-template-columns: 1fr 1fr;
}
div.d {
    width: 200px;
    height: 200px;
    background-color: red;
    margin:20px;
    font-size:50px;
    text-align: center;
}
.flex{
    border:1px solid black;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.second{
    height:900px;
    border:1px solid black;
}
.this{
    justify-self: flex-end;
}
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div class="flex">
    <div class="d">1</div>
    <div class="d">2</div>
    <div class="d this">3</div>
</div>
<div class="second">
    <div class="d"></div>
    <div class="d"></div>
    <div class="d"></div>
    <div class="d"></div>
</div>

</body>
</html>
Flo
  • 29
  • 5
  • Do you want the number 3 to be on the bottom or you wish to enlarge the box so its height its equal as the other column? – Eduardo Dec 02 '20 at 19:36
  • I want number 3 on the bottom while the rest are starting from the top. – Flo Dec 02 '20 at 19:38
  • I was able to do what you wanted but the question got closed ha! No worries, another solution is to nest the number 3, inside that div, with a span element and then applying flexbox properties to the nested item. – Eduardo Dec 02 '20 at 19:46

1 Answers1

0

Try playing with margins:

body{
    display: grid;
    grid-template-columns: 1fr 1fr;
}
div.d {
    width: 200px;
    height: 200px;
    background-color: red;
    margin:20px 20px 0;
    font-size:50px;
    text-align: center;
}
.flex{
    border:1px solid black;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.second{
    height:900px;
    border:1px solid black;
}
div.this{
    margin: auto 20px 20px;
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>

  <div class="flex">
    <div class="d">1</div>
    <div class="d">2</div>
    <div class="d this">3</div>
  </div>
  <div class="second">
    <div class="d"></div>
    <div class="d"></div>
    <div class="d"></div>
    <div class="d"></div>
  </div>

</body>

</html>
Kosh
  • 16,966
  • 2
  • 19
  • 34