DEV/javascript

Bootstrap 부트스트랩 Grid 사용하기 2 : Grid (Row, Col)

석봉 2022. 5. 3. 20:53

부트 스트랩을 이용하여 화면 분할 방법

(Container 및 Grid를 이용하여 반응형으로 화면을 만들어보자)

2. Grid (Row, Col)

Bootstrap에서는 편리한 화면 구성을 위해 그리드 시스템을 제공한다.

 

Boostrap은 총 12 분할을 기준으로 화면 구성을 지원한다.

 

하단 코드와 그림을 보면 한 번에 이해가 가능할 것이다.

(container는 container-fluid를 사용했다.)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
    
    <!-- [Bootstrap] -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

    <!-- 테스트를 위한 CSS -->
    <style>
        div {
            height: 200px;
            text-align: center;
        }
    </style>
</head>
<body>
    <!-- .container-fluid, which is width: 100% at all breakpoints -->
    <div class="container-fluid" style="background-color: gray;">
        <div class="row">
            <!-- row 1 (total : 12) -->
            <div class="col-4" style="background-color: #F8ECD1;">
                Bootstrap 에서는<br>(col-4)
            </div>
            <div class="col-4" style="background-color: #DEB6AB;">
                12칸 분할을 기준으로<br>(col-4)
            </div>
            <div class="col-4" style="background-color: #AC7D88;">
                합니다.<br>(col-4)
            </div>

            <!-- row 2 (total : 12) -->
            <div class="col-3" style="background-color: #A2B38B;">
                총 너비인 12칸을<br>(col-3)
            </div>
            <div class="col-6" style="background-color: #E4E9BE;">
                넘는 경우에는<br>(col-6)
            </div>
            <div class="col-3" style="background-color: #FAFDD6;">
                다음 줄로 넘어갑니다.<br>(col-3)
            </div>

            <!-- row 3 (total : 12) -->
            <div class="col-2" style="background-color: #F8B400;">
                다음과 같이<br>(col-2)
            </div>
            <div class="col" style="background-color: #FAF5E4;">
                사용 또한<br>(col, 남는 자리 자동 할당)
            </div>
            <div class="col-3" style="background-color: #FF6363;">
                가능합니다..<br>(col-3)
            </div>
        </div>
    </div>
</body>
</html>

출력 결과

.row는 내부 요소를 세로 방향으로 쌓는다.

.col은 row 내부에서 가로 방향으로  요소를 정렬한다.

 

.col-n은 요소의 크기(가로길이)를 n 비율만큼 사용한다.

( n은 12까지 사용이 가능하며 총 12개의 크기로 분할이 가능하다. )

 

이 row와 col을 적절하게 사용하면 쉽게 화면 구성이 가능하다.

 

다음 장에서 간단한 화면 구성 예시와 Bootstrap의 margin, padding 사용법을 알아보자.


다음 편은 아래 링크에서!

https://seokbong.tistory.com/82

 

Bootstrap 부트스트랩 Grid 사용하기 3 : 반응형 Grid 구성

부트 스트랩을 이용하여 화면 분할 방법 (Container 및 Grid를 이용하여 반응형으로 화면을 만들어보자) 3. Grid (반응형) 간단한 col, row 응용과 반응형 화면을 구성해 보았다. 코드를 보면 충분히 쉽게

seokbong.tistory.com

(이 전편)

https://seokbong.tistory.com/80

 

Bootstrap 부트스트랩 Grid 사용하기 1 : Container

부트 스트랩을 이용하여 화면 분할 방법 (Container 및 Grid를 이용하여 반응형으로 화면을 만들어보자) 1. Container 우선 화면의 콘텐츠를 분할을 하기 전에 해당 콘텐츠를 담을 Container에 대해 간단하

seokbong.tistory.com

ref : Bootstrap Grid system

https://getbootstrap.com/docs/5.1/layout/grid/

 

Grid system

Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, six default responsive tiers, Sass variables and mixins, and dozens of predefined classes.

getbootstrap.com

ref : 예전 포스트에서 그리드 시스템을 다룬 적 있다. (대충 비슷한 내용)

https://seokbong.tistory.com/17

 

Bootstrap 그리드 시스템 (Grid system : row, col)

성격 급한 사람을 위한 빠른 코드! 작은 사이즈, 4/12 만큼 공간을 차지 작은 사이즈, 8/12 만큼 공간을 차지 HTML 화면을 배치하고 꾸미는 것이 참으로 난감하다. 특히 나처럼 미적 감각이 1도 없는

seokbong.tistory.com