정보실

웹학교

정보실

bootstrap Bootstrap 4 Sticky Sidebars (PURE CSS)

본문

CSS와 부트스트랩4만을 이용한 멀티 스틱키 메뉴 구현...


https://codepen.io/ncerminara/pen/VdLpzd


링크 : https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css


HTML :

<article>
    <div class="container-fluid">
        <div class="row">
            <div class="col">
                <div class="title-section">
                    <h1>Multiple Stacking Sticky Sidebars with Bootstrap 4</h1>
                    <p class="lead">This is 100% CSS</p>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-1 has-10-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 1</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 2</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 3</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 4</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 5</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 6</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 7</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 8</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 9</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 10</h4>
                    </div>
                </div>


            </div>
            <div class="col-5">

                <div class="content-section">
                    <h2>Content Section</h2>
                </div>
            </div>
            <div class="col-3 has-4-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 1</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 2</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 3</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 4</h3>
                    </div>
                </div>

            </div>
            <div class="col-2 has-2-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 1</h3 class="alt">
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 2</h3 class="alt">
                    </div>
                </div>
            </div>

            <div class="col-1 has-3-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 1</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 2</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 3</h5>
                    </div>
                </div>
            </div>


        </div>
    </div>
</article>
<article>
    <div class="container-fluid">
        
        <div class="row">
            
            <div class="col-3">

                <div class="content-section">
                    <h2>Content Section</h2>
                </div>
            </div>
               <div class="col-2 has-3-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 1</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 2</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 3</h5>
                    </div>
                </div>
            </div>

            <div class="col-2 has-4-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 1</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 2</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 3</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 4</h3>
                    </div>
                </div>

            </div>
            <div class="col-2 has-2-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 1</h3 class="alt">
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 2</h3 class="alt">
                    </div>
                </div>
            </div>

            <div class="col-3 has-10-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 1</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 2</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 3</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 4</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 5</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 6</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 7</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 8</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 9</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 10</h4>
                    </div>
                </div>


            </div>

         

        </div>
    </div>
</article>
<article>
    <div class="container-fluid">
       
        <div class="row">
            <div class="col-1 has-10-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 1</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 2</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 3</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 4</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 5</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 6</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 7</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 8</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 9</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 10</h4>
                    </div>
                </div>


            </div>
            <div class="col-5">

                <div class="content-section">
                    <h2>Content Section</h2>
                </div>
            </div>
            <div class="col-3 has-4-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 1</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 2</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 3</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 4</h3>
                    </div>
                </div>

            </div>
            <div class="col-2 has-2-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 1</h3 class="alt">
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 2</h3 class="alt">
                    </div>
                </div>
            </div>

            <div class="col-1 has-3-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 1</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 2</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 3</h5>
                    </div>
                </div>
            </div>


        </div>
    </div>
</article>
<article>
    <div class="container-fluid">
        
        <div class="row">
            
            <div class="col-3">

                <div class="content-section">
                    <h2>Content Section</h2>
                </div>
            </div>
               <div class="col-2 has-3-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 1</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 2</h5>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h5>Item 3</h5>
                    </div>
                </div>
            </div>

            <div class="col-2 has-4-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 1</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 2</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 3</h3>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3>Item 4</h3>
                    </div>
                </div>

            </div>
            <div class="col-2 has-2-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 1</h3 class="alt">
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h3 class="alt">Item 2</h3 class="alt">
                    </div>
                </div>
            </div>

            <div class="col-3 has-10-items">

                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 1</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 2</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 3</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 4</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 5</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 6</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 7</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 8</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 9</h4>
                    </div>
                </div>
                <div class="sidebar-item">
                    <div class="make-me-sticky">
                        <h4>Item 10</h4>
                    </div>
                </div>


            </div>

         

        </div>
    </div>
</article>


CSS :

.content-section {
  min-height: 2000px;
}

.sidebar-section {
  position: absolute;
  height: 100%;
  width: 100%;
}

.sidebar-item {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}

.has-4-items .sidebar-item {
  height: 25%;
}
.has-4-items .sidebar-item:nth-child(2) {
  top: 25%;
}
.has-4-items .sidebar-item:nth-child(3) {
  top: 50%;
}
.has-4-items .sidebar-item:nth-child(4) {
  top: 75%;
}

.has-3-items .sidebar-item {
  height: 33.333333%;
}
.has-3-items .sidebar-item:nth-child(2) {
  top: 33.333333%;
}
.has-3-items .sidebar-item:nth-child(3) {
  top: 66.666666%;
}

.has-2-items .sidebar-item {
  height: 50%;
}
.has-2-items .sidebar-item:nth-child(2) {
  top: 50%;
}

.has-10-items .sidebar-item {
  height: 10%;
}
.has-10-items .sidebar-item:nth-child(2) {
  top: 10%;
}
.has-10-items .sidebar-item:nth-child(3) {
  top: 20%;
}
.has-10-items .sidebar-item:nth-child(4) {
  top: 30%;
}
.has-10-items .sidebar-item:nth-child(5) {
  top: 40%;
}
.has-10-items .sidebar-item:nth-child(6) {
  top: 50%;
}
.has-10-items .sidebar-item:nth-child(7) {
  top: 60%;
}
.has-10-items .sidebar-item:nth-child(8) {
  top: 70%;
}
.has-10-items .sidebar-item:nth-child(9) {
  top: 80%;
}
.has-10-items .sidebar-item:nth-child(10) {
  top: 90%;
}

.make-me-sticky {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  padding: 0 15px;
}

/* Ignore This, just coloring */
body {
  background: #fff;
}

article {
  background: #f1f1f1;
  border-radius: 12px;
  padding: 25px 0;
}

.title-section, .content-section, .sidebar-section {
  background: #fff;
}

.title-section {
  text-align: center;
  padding: 50px 15px;
  margin-bottom: 30px;
}

.content-section h2 {
  text-align: center;
  margin: 0;
  padding-top: 200px;
}

.sidebar-item {
  text-align: center;
}
.sidebar-item h3 {
  background: gold;
  max-width: 100%;
  margin: 0 auto;
  padding: 50px 0 100px;
  border-bottom: solid 1px #fff;
}
.sidebar-item h3.alt {
  background: pink;
}
.sidebar-item h4 {
  padding: 25px 0;
  background: orange;
  border-bottom: solid 1px #fff;
  font-size: 12px;
}
.sidebar-item h5 {
  padding: 25px 0;
  background: lightgreen;
  border-bottom: solid 1px #fff;
  font-size: 12px;
}

body {
  padding-bottom: 1000px;
}


  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기
  • 카카오톡으로 보내기

페이지 정보

조회 127회 ]  작성일18-06-07 21:50

웹학교