Home > Enterprise >  Flex-end is not working on a button inside a div with display of flex
Flex-end is not working on a button inside a div with display of flex

Time:12-07

So I feel like I have tried everything to make this button go to the bottom of the div but nothing seems to work. If I switch the container div to align-content: flex-end everything moves to the bottom as it should but I am trying to keep the divs at the top and only bring down the button. I am using React and CSS Modules.

import styles from './Total.module.css';

const Total = ({ tipTotal, total, handleReset }) => {
  return (
    <div className={styles.total}>
      <div className={styles.totalTipAmount}>
        <div className={styles.totalLeft}>
          <div className={styles.totalTop}>Tip Amount</div>
          <div className={styles.totalBottom}>/ person</div>
        </div>
        <div className={styles.totalRight}>${tipTotal}</div>
      </div>
      <div className={styles.toalAmount}>
        <div className={styles.totalLeft}>
          <div className={styles.totalTop}>Total</div>
          <div className={styles.totalBottom}>/ person</div>
        </div>
        <div className={styles.totalRight}>${total}</div>
      </div>
      <button className={styles.totalReset} onClick={handleReset}>
        RESET
      </button>
    </div>
  );
};

export default Total;
.total {
  display: flex;
  align-self: center;
  flex-direction: column;
  width: 80%;
  min-width: 80%;
  margin: 30px 0;
  background-color: var(--Very-dark-cyan);
  border-radius: 15px;
  padding: 30px 15px 5px 15px;
}

.total div {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  justify-self: flex-start;
}

.totalLeft {
  display: flex;
  flex-direction: column;
}

.totalTop {
  color: var(--White);
  font-size: medium;
  margin-bottom: 5px !important;
}

.totalBottom {
  font-size: small;
  color: var(--Dark-blueish-cyan);
}

.totalRight {
  font-size: xx-large;
  color: var(--Strong-cyan);
}

.total button {
  background-color: var(--Strong-cyan);
  color: var(--Very-dark-cyan);
  font-size: large;
  font-weight: 700;
  width: 100%;
  max-width: 100%;
}

@media (min-width: 900px) {
  .total {
    height: 100%;
    grid-column-start: 2;
    grid-row-start: 1;
    grid-row-end: 4;
    justify-self: center;
  }

  .total button {
    align-self: flex-end;
  }
}

CodePudding user response:

enter image description hereremove width:100% from button tag css

CodePudding user response:

    .total {
    height: 100%;
    grid-column-start: 2;
    grid-row-start: 1;
    grid-row-end: 4;
    justify-self: center;
    position:relative;
  }
  .total button {
    align-self: flex-end;
    position: absolute;
    right: 20px;
  }

CodePudding user response:

body, html {
  height: 100%;
}
.total {
  display: flex;
  flex-direction: column;
  width: 80%;
  min-width: 80%;
  margin: 30px 0;
  background-color: var(--Very-dark-cyan);
  border-radius: 15px;
  padding: 30px 15px 5px 15px;
  height: 80%;
  border: 1px solid red;
  justify-content: space-between;
}

.totalTipAmount, .totalAmount {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.totalLeft {
  display: flex;
  flex-direction: column;
}

.totalTop {
  color: var(--White);
  font-size: medium;
  margin-bottom: 5px !important;
}

.totalBottom {
  font-size: small;
  color: var(--Dark-blueish-cyan);
}

.totalRight {
  font-size: xx-large;
  color: var(--Strong-cyan);
}

.totalReset {
  justify-self: flex-end;
  border: 1px solid blue;
}

.total button {
  background-color: var(--Strong-cyan);
  color: var(--Very-dark-cyan);
  font-size: large;
  font-weight: 700;
  width: 100%;
  max-width: 100%;
}

@media (min-width: 900px) {
  .total {
    height: 100%;
    grid-column-start: 2;
    grid-row-start: 1;
    grid-row-end: 4;
    justify-self: center;
  }

  .total button {
    align-self: flex-end;
  }
}
 <div class="total">
   <div class="stuffAtTheTop">
     <div class="totalTipAmount">
       <div class="totalLeft">
         <div class="totalTop">Tip Amount</div>
         <div class="totalBottom"}>/ person</div>
       </div>
       <div class="totalRight">${tipTotal}</div>
     </div>
     <div class="totalAmount">
       <div class="totalLeft">
         <div class="totalTop">Total</div>
         <div class="totalBottom">/ person</div>
       </div>
       <div class="totalRight">${total}</div>
     </div>
   </div>
   <button class="totalReset">
     RESET
   </button>
  </div>
</div>
    
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related