본문 바로가기
개발/CSS

align-self, align-items, align-content

by 안뇽! 2022. 2. 13.
반응형

  • align-self : 자신에게 적용
  • align-items : 자식이 외동일때만 자식에게 적용, 
  • align-content : 자식이 여럿일때, 여럿에게 적용

align-self : 자신에게 적용

.containor .flex-wrapper {
  /* margin-top: 30px; */
  align-self: center;
  background: #e6e8ec;
  border: none;
  color: black;
  display: flex;
  flex-direction: column;
}

자신에게 center가 적용된다.

align-items : 자식들에게 적용

.containor .flex-wrapper {
  /* margin-top: 30px; */
  align-items: center;
  background: #e6e8ec;
  border: none;
  color: black;
  display: flex;
  flex-direction: column;
}

자식들에게 center가 적용된다.

 

align-content

<div class="white-wrapper">
          <div class="icon num1"><strong>박지성</strong> SBS에서 월드컵보세요!</div>
          <div class="icon num2"><strong>안정환</strong> MBC죠...</div>
          <div class="icon num3"><strong>이영표</strong> KBS는 수신료의 가치를..</div>
</div>

.white-wrapper {
  border: purple 1px solid;
  width: 100%;
  height: 300px;
  display: flex;
  flex-wrap: wrap;

  align-self: flex-start; //* align-self는 안먹음. 자식요소가 3개이기 때문
  //* align-content : flex-start; *//
  //* align-content : center; *//
  //* align-content : flex-end; *//
}

좌: flex-start, 중: center, 우: flex-end


코드

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>CSS 연습</title>
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
    <div class="containor">
      <span>고객님, 안녕하세요?</span>
      <div class="flex-wrapper">
        <span>페이스북 색감따라하기</span>
        <div>
          <div class="icon num1"><strong>박지성</strong> SBS에서 월드컵보세요!</div>
          <div class="icon num2"><strong>안정환</strong> MBC죠...</div>
          <div class="icon num3"><strong>이영표</strong> KBS는 수신료의 가치를..</div>
        </div>
      </div>
    </div>
  </body>
</html>

index.css

body {
  margin: 0 auto;
  width: 500px;
}
.containor {
  background: #405ba4;
  color: white;
  font-size: 2rem;
  display: flex;
  flex-direction: column;
  /* align-items: center; */
}
.containor span {
  padding: 30px;
}

.containor .flex-wrapper {
  /* margin-top: 30px; */
  /* align-self: center; */
  background: #e6e8ec;
  border: none;
  color: black;
  display: flex;
  flex-direction: column;
}
.white-wrapper {
  border: purple 1px solid;
  width: 100%;
  height: 300px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-end;
}
.containor .flex-wrapper .icon {
  margin-bottom: 30px;

  padding: 5px;
  background: white;
  color: black;
}
반응형