Computer >> 컴퓨터 >  >> 프로그래밍 >> CSS

CSS에서 플렉스 항목 사이에 공백 추가하기 – justify-content 활용법

플렉스 컨테이너 안의 항목들 사이에 공백을 추가하려면 justify-content 속성에 space-between 값을 지정하면 됩니다. 이 값을 사용하면 첫 번째 항목은 컨테이너의 시작점에, 마지막 항목은 끝점에 배치되고, 나머지 항목들은 그 사이에 균등한 간격으로 정렬됩니다.

예제

아래 코드를 실행하면 space-between 값을 실제로 어떻게 구현하는지 확인할 수 있습니다.

<!DOCTYPE html>
<html>
   <head>
      <style>
         .mycontainer {
            display: flex;
            background-color: red;
            justify-content: space-between;
         }
         .mycontainer > div {
            background-color: white;
            text-align: center;
            line-height: 60px;
            font-size: 30px;
            width: 100px;
            margin: 5px;
         }
      </style>
   </head>
   <body>
      <h1>Quiz</h1>
      <div class = "mycontainer">
         <div>Q1</div>
         <div>Q2</div>
         <div>Q3</div>
         <div>Q4</div>
      </div>
   </body>
</html>