메뉴 건너뛰기

프로그램언어

조회 수 428 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

css display 속성 중 flex 속성이 존재한다.

flex 속성을 활용하여 정렬하는 방법을 알아보겠다.

 

 

flex-direction 속성을 통해 수평 정렬 (row)

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <style media="screen">
    *{
      margin: 0;
      padding: 0;
    }
    body{
      height: 100vh;
      display: flex;
      flex-wrap: wrap;
      flex-direction: row; /*수평 정렬*/
      align-items: center;
      justify-content: center;
    }
    div{
      width: 60px;
      height: 60px;
      background: #0054FF;
      margin: 10px;
    }
  </style>
  <body>
    <div class="one"></div>
    <div class="two"></div>
    <div class="three"></div>
    <div class="four"></div>
  </body>
</html>

 

 

수평 정렬

 

 


 

flex-direction 속성을 통해 수직 정렬(column)

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <style media="screen">
    *{
      margin: 0;
      padding: 0;
    }
    body{
      height: 100vh;
      display: flex;
      flex-wrap: wrap;
      flex-direction: column; /*수직 정렬*/
      align-items: center;
      justify-content: center;
    }
    div{
      width: 60px;
      height: 60px;
      background: #0054FF;
      margin: 10px;
    }
  </style>
  <body>
    <div class="one"></div>
    <div class="two"></div>
    <div class="three"></div>
    <div class="four"></div>
  </body>
</html>

 

 

수직 정렬

 

display flex 정렬은 감싸는 태그의 사이즈에 맞추어 적용되는 속성으로 body 태그에 높이 100vh를 적용하여 전체 높이에 맞추어 수직 수평 정렬을 적용하였다.

align-items는 flex 내부 항목 열을 정렬한다.

적용 가능한 값

stretch

flex-start

flex-end

center

justify-content는 flex 내부 항목의 행을 정렬한다.

적용 가능한 값

stretch

flex-start

flex-end

center

space-around

space-betweenspace-evenl


flex 속성을 사용하게 되면 flex-wrap 속성을 통해 줄 별로 정렬도 가능하다.

flex-wrap 속성을 사용하지 않으면 default값으로 nowrap 이 적용되어 넓이를 초과하더라도 아랫줄로 이동하지 않는다.

flex-wrap 속성 변경을 통한 줄 변경(wrap)

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <style media="screen">
    *{
      margin: 0; padding: 0;
    }
    .box{
      width: 240px;
      display: flex;
      flex-wrap: wrap; /*줄 바꿈*/
      outline: 1px solid black;
    }
    .box div{
      width: 60px;
      height: 60px;
      background: #0054FF;
      margin: 10px;
    }
  </style>
  <body>
    <div class="box">
      <div class="one"></div>      <div class="two"></div>      <div class="three"></div>      <div class="four"></div>
    </div>
  </body>
</html>

 

wrap 속성을 통한 줄바꿈

 

 

 

nowrap 속성 상태

 

 

wrap 속성이 없어지면 nowrap으로 처리되어 자동으로 넓이가 적용된다.


List of Articles
번호 제목 날짜 조회 수
32 웹 브라우저에 [가로 스크롤 안생기게 하기] 2016.12.23 15131
31 input box 테두리 없애기 2016.12.23 9667
30 네이버 나눔글꼴 적용 2014.03.01 6666
29 <iframe>으로 올린 유투브 동영상 z-index 문제 2015.02.03 6644
28 Box CSS file 2014.02.27 6468
27 HTML 목록 태그와 CSS를 활용하여 깔끔한 목록 스타일을 만드는 방법 / CSS list-style file 2016.12.22 6178
26 CSS : 반응형 웹(Responsive Web) file 2017.04.14 5938
25 background-size 속성 2016.12.23 5874
24 둥근 모서리 박스 css 2014.02.27 5854
23 CSS3를 이용하여 둥근모서리 박스 만들기 2016.12.22 5840
22 메뉴 텍스트(text)에 그림자 효과 주기 2014.02.27 5806
21 하이퍼링크 & 링크이미지에 점선을 죽임 2016.12.23 5748
20 폼을 투명하게 2016.12.23 5234
19 기본적으로 보이는 스크롤바를 없애기 2016.12.23 5118
18 모바일 체크박스 변경 마크업 2015.02.03 4968
17 텍스트 ime모드 속성 2016.12.23 4961
16 중급 사용자를 위한 CSS 선택자에 관한 지식 / CSS에서 마우스 동작을 감지하는 방법 2016.12.22 4960
15 css를 이용한 테이블 가운데 정렬 2016.12.22 4856
14 인쇄할때 페이지 나누는 br 태그 2016.12.23 4775
13 CSS background-repeat 이해하기 2016.12.22 4738
Board Pagination Prev 1 2 Next
/ 2

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved