ForestProgramming
ForestProgramming

Reputation: 83

HTML-CSS DIV Element Not Starting From Bottom of Container

I am trying to have each bar begin from the bottom but they begin from the top of the container. How can I align them at the bottom of the container. I tried `vertical-align: bottom

.phase-balancing-bar-graph-container{
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: pink;
  height: 100vh;
  padding: 20px;
}
.phase-balancing-bar-graph-container .graph-wrapper{
  position: absolute;
  width: 55%;
  display: flex;
  justify-content: space-between;
  background-color: grey;
  height: calc(100% - 65%);
  top: 10%;
  padding: 0 20px 0 20px
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container{
  position: relative;
  width: 60px;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar-phase-label{
  display: flex;
  justify-content: center;
  align-items: center;
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.a{
  background-color: #BA55D3;
  transition: 0.5s ease;
  height: 25%;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.b{
  background-color: #FF8C00;
  transition: 0.5s ease;
  height: 40%;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.c{
  background-color: #81C784;
  transition: 0.5s ease;
  height: 70%;
}
<div class="phase-balancing-bar-graph-container">
  <div class="graph-wrapper">
    <div class="bar-container">
      <div class="bar-phase-label">A</div>
      <div class="bar a"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">B</div>
      <div class="bar b"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">C</div>
      <div class="bar c"></div>
    </div>
  </div>
</div>

` but it didnt work. Not sure what I am doing wrong. I have tried other stuff but it isn't working. I have attached my code to this post. Please run code to understand. Thank you

Upvotes: 0

Views: 60

Answers (3)

Arman Ebrahimi
Arman Ebrahimi

Reputation: 2297

Try this:

I used flex for elements. Also I removed position: absolute; top: 10%; and position: relative from .graph-wrapper and .bar-container. No need to them. So I used padding at .graph-wrapper for a distance with border-bottom:

.phase-balancing-bar-graph-container{
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: pink;
  height: 100vh;
  padding: 20px;
}
.phase-balancing-bar-graph-container .graph-wrapper{
  width: 55%;
  display: flex;
  justify-content: space-between;
  background-color: grey;
  height: calc(100% - 65%);
  padding: 10px 20px;  /*here*/
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container{
  width: 15%; /*here*/
  display: flex; /*here*/
  flex-direction: column; /*here*/
  justify-content: flex-end; /*here*/
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar-phase-label{
  display: flex;
  justify-content: center;
  align-items: center;
  height:30%; /*here*/
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.a{
  background-color: #BA55D3;
  transition: 0.5s ease;
  height: 25%;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.b{
  background-color: #FF8C00;
  transition: 0.5s ease;
  height: 40%;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.c{
  background-color: #81C784;
  transition: 0.5s ease;
  height: 70%;
}
<div class="phase-balancing-bar-graph-container">
  <div class="graph-wrapper">
    <div class="bar-container">
      <div class="bar-phase-label">A</div>
      <div class="bar a"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">B</div>
      <div class="bar b"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">C</div>
      <div class="bar c"></div>
    </div>
  </div>
</div>

Upvotes: 0

user18332436
user18332436

Reputation:

Please try this code

.phase-balancing-bar-graph-container{
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: pink;
  height: 100vh;
  padding: 20px;
}
.phase-balancing-bar-graph-container .graph-wrapper{
  position: absolute;
  width: 55%;
  display: flex;
  justify-content: space-between;
  background-color: grey;
  height: calc(100% - 65%);
  top: 10%;
  padding: 0 20px 0 20px
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container{
  position: relative;
  width: 60px;
  display: flex;
  flex-direction: column;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar-phase-label{
  display: flex;
  justify-content: center;
  align-items: flex-start;
  flex: 1 0 auto;
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.a{
  background-color: #BA55D3;
  transition: 0.5s ease;
  height: 25%;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.b{
  background-color: #FF8C00;
  transition: 0.5s ease;
  height: 40%;
}
.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.c{
  background-color: #81C784;
  transition: 0.5s ease;
  height: 70%;
}
<div class="phase-balancing-bar-graph-container">
  <div class="graph-wrapper">
    <div class="bar-container">
      <div class="bar-phase-label">A</div>
      <div class="bar a"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">B</div>
      <div class="bar b"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">C</div>
      <div class="bar c"></div>
    </div>
  </div>
</div>

Upvotes: 0

prograk
prograk

Reputation: 581

you need to add this code in css

 .phase-balancing-bar-graph-container .graph-wrapper .bar-container {
    position: relative;
    width: 60px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

.phase-balancing-bar-graph-container {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: pink;
  height: 100vh;
  padding: 20px;
}

.phase-balancing-bar-graph-container .graph-wrapper {
  position: absolute;
  width: 55%;
  display: flex;
  justify-content: space-between;
  background-color: grey;
  height: calc(100% - 65%);
  top: 10%;
  padding: 0 20px 0 20px;
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container {
  position: relative;
  width: 60px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar-phase-label {
  display: flex;
  justify-content: center;
  align-items: center;
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.a {
  background-color: #ba55d3;
  transition: 0.5s ease;
  height: 25%;
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.b {
  background-color: #ff8c00;
  transition: 0.5s ease;
  height: 40%;
}

.phase-balancing-bar-graph-container .graph-wrapper .bar-container .bar.c {
  background-color: #81c784;
  transition: 0.5s ease;
  height: 70%;
}
<div class="phase-balancing-bar-graph-container">
  <div class="graph-wrapper">
    <div class="bar-container">
      <div class="bar-phase-label">A</div>
      <div class="bar a"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">B</div>
      <div class="bar b"></div>
    </div>
    <div class="bar-container">
      <div class="bar-phase-label">C</div>
      <div class="bar c"></div>
    </div>
  </div>
</div>

Upvotes: 2

Related Questions