테스트 사이트 - 개발 중인 베타 버전입니다

css의 position속성 중 sticky가 적용이 안돼서 질문드립니다. 채택완료

aiai1505150 1년 전 조회 21,026

안녕하세요! 지금 html, css기초 하는 중인데 css의 position속성 중 sticky가 적용이 안돼서 질문드립니다..

구글링 해서 align-self도 해보고 z-index도 해보고 부모 요소의 heigh을 설정하면 밑 태그들이 뒤로 밀려나서 어떨게 해야할지 모르겠습니다 ㅜㅜ

아래 코드중 class="k"부분을 sticky top 0px을 하고싶은데 어디를 어떻게 고치면 좋을까요..?

밑 p태그들은 임의로 작성해 놓은 것입니다..!

 

</strong></p>

<p>    body{</p>

<p>         margin: 0px;</p>

<p>        }</p>

<p>    .title{</p>

<p>        position: relative;</p>

<p>        top: 0px;</p>

<p>        width: 100%;</p>

<p>        display: flex;</p>

<p>        flex-direction: column;</p>

<p>        position: fixed;</p>

<p>        top:0px;</p>

<p>        background-color: white;</p>

<p> </p>

<p>    }</p>

<p>    .sale{</p>

<p>        box-sizing: border-box;</p>

<p>        width: 100%;</p>

<p>        background-color: #73864f;</p>

<p>        text-align: center;</p>

<p>        height: 35px;</p>

<p> </p>

<p>    }</p>

<p>    .text{</p>

<p>        box-sizing: border-box;</p>

<p>        height: 35px;</p>

<p>        margin: 0px;</p>

<p>        padding-top: 9px;</p>

<p>        padding-bottom: 9px;</p>

<p>        color: white;</p>

<p>        font-size: 13px;</p>

<p>    }</p>

<p>    .name{</p>

<p>        width: 100%;</p>

<p>        box-sizing: border-box;</p>

<p>        display: flex;</p>

<p>        justify-content: space-between;</p>

<p>        padding-right: 150px;</p>

<p>        padding-left: 150px;</p>

<p>        margin-top: 10px;</p>

<p>       </p>

<p>    }</p>

<p>    .logo{</p>

<p>        box-sizing: border-box;</p>

<p>        width: 250px;</p>

<p>        height: 70px;</p>

<p>        background-image: url(./salad.jpg);</p>

<p>        background-size: 70px 70px;</p>

<p>        background-repeat: no-repeat;</p>

<p>        background-position: left;</p>

<p>        padding-bottom: 12px;</p>

<p>        padding-top: 12px;</p>

<p>        padding-left: 80px;</p>

<p>}</p>

<p>       </p>

<p>       .logo1{</p>

<p>        box-sizing: border-box;</p>

<p>        margin: 0px;</p>

<p>        width: 170px;</p>

<p>        color: #73864f;</p>

<p>        font-size: 28px;</p>

<p>       }</p>

<p>       .logo2{</p>

<p>        box-sizing: border-box;</p>

<p>        margin: 0px;</p>

<p>        width: 170px;</p>

<p>        font-size: 12px;</p>

<p>        text-align: center;</p>

<p>        padding-right: 15px;</p>

<p>        color: #73864f;</p>

<p>       }</p>

<p>       .lit{</p>

<p>        display: flex;</p>

<p>       }</p>

<p>       .lit2{</p>

<p>        box-sizing: border-box;</p>

<p>        width: 63px;</p>

<p>        height: 70px;</p>

<p>        padding: 23px 0px;</p>

<p>        text-align: center;</p>

<p>        color: gray;</p>

<p>        font-size: 12px;</p>

<p>       }</p>

<p>       .lit2:hover{</p>

<p>        color:#73864f;</p>

<p>       }</p>

<p>       .k{</p>

<p>       width: 100%;</p>

<p>       background-color: white;</p>

<p>       position: sticky;</p>

<p>       top: 0px;</p>

<p>       z-index: 100;</p>

<p>       }</p>

<p>    .list{</p>

<p>        display: flex;</p>

<p>        width: 750px;</p>

<p>        justify-content: space-around;</p>

<p>        box-sizing: border-box;</p>

<p>        padding-left: 150px;</p>

<p>        margin-top: 20px;</p>

<p>        background-color: white;</p>

<p>       </p>

<p>    }</p>

<p>    .imgg{</p>

<p>        width: 20px;</p>

<p>        height: 20px;</p>

<p>        background-image: url(./bar.png);</p>

<p>        background-repeat: no-repeat;</p>

<p>        background-size: contain;</p>

<p>       }</p>

<p>       .list2{</p>

<p>        display: block;</p>

<p>        box-sizing: border-box;</p>

<p>        width: 72px;</p>

<p>        height: 24px;</p>

<p>        text-align: center;</p>

<p>        font-size: 17px;</p>

<p>       }</p>

<p>       .list3{</p>

<p>        display: block;</p>

<p>        box-sizing: border-box;</p>

<p>        width: 90px;</p>

<p>        height: 24px;</p>

<p>        text-align: center;</p>

<p>        font-size: 17px;</p>

<p>       }</p>

<p>       .list4{</p>

<p>        display: block;</p>

<p>        box-sizing: border-box;</p>

<p>        width: 58px;</p>

<p>        height: 24px;</p>

<p>        text-align: center;</p>

<p>        font-size: 17px;</p>

<p>       }</p>

<p>       .list5{</p>

<p>        display: block;</p>

<p>        box-sizing: border-box;</p>

<p>        width: 58px;</p>

<p>        height: 24px;</p>

<p>        text-align: center;</p>

<p>        font-size: 17px;</p>

<p>       }</p>

<p>       .list6{</p>

<p>        display: block;</p>

<p>        box-sizing: border-box;</p>

<p>        width: 41px;</p>

<p>        height: 24px;</p>

<p>        text-align: center;</p>

<p>        font-size: 17px;</p>

<p>       }</p>

<p>       .list7{</p>

<p>        display: block;</p>

<p>        box-sizing: border-box;</p>

<p>        width: 58px;</p>

<p>        height: 24px;</p>

<p>        text-align: center;</p>

<p>        font-size: 17px;</p>

<p>       }</p>

<p> </p>

<p>   </p>

<p></style></p>

<p><body></p>

<p>    <div class="title"></p>

<p>        <div class="sale"></p>

<p>           <p class="text">지금 가입하면 3만원 쿠폰팩 지급!</p></p>

<p>        </div></p>

<p>        <div class="name"></p>

<p>          <div class="logo"></p>

<p>              <h3 class="logo1">SALADMEAL</h3></p>

<p>              <p class="logo2">salad & mealkit</p></p>

<p>          </div></p>

<p>          <div class="lit"></p>

<p>              <span class="lit2">로그인</span></p>

<p>              <span class="lit2">회원가입</span></p>

<p>              <span class="lit2">주문내역</span></p>

<p>              <span class="lit2">고객센터</span></p>

<p>          </div></p>

<p>        </div></p>

<p>        <div class="k"></p>

<p>         <div class="list"></p>

<p>            <span class="imgg"></span></p>

<p>            <span class="list2">카테고리</span></p>

<p>            <span class="list3">샐드밀소개</span></p>

<p>            <span class="list4">베스트</span></p>

<p>            <span class="list5">샐러드</span></p>

<p>            <span class="list6">포케</span></p>

<p>            <span class="list7">이벤트</span></p>

<p>         </div></p>

<p>        </div></p>

<p>    </div></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p><P>1</P></p>

<p></body></p>

<p></html></p>

<p><strong>
 

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트
1년 전

</p>

<p><html>

<style>

    body{

         margin: 0px;

        }

    .title{

        position: relative;

        top: 0px;

        width: 100%;

        display: flex;

        flex-direction: column;

        /* position: fixed; */

        top:0px;

        background-color: white;

 

    }

    .sale{

        box-sizing: border-box;

        width: 100%;

        background-color: #73864f;

        text-align: center;

        height: 35px;

 

    }

    .text{

        box-sizing: border-box;

        height: 35px;

        margin: 0px;

        padding-top: 9px;

        padding-bottom: 9px;

        color: white;

        font-size: 13px;

    }

    .name{

        width: 100%;

        box-sizing: border-box;

        display: flex;

        justify-content: space-between;

        padding-right: 150px;

        padding-left: 150px;

        margin-top: 10px;

       

    }

    .logo{

        box-sizing: border-box;

        width: 250px;

        height: 70px;

        background-image: url(./salad.jpg);

        background-size: 70px 70px;

        background-repeat: no-repeat;

        background-position: left;

        padding-bottom: 12px;

        padding-top: 12px;

        padding-left: 80px;

}

       

       .logo1{

        box-sizing: border-box;

        margin: 0px;

        width: 170px;

        color: #73864f;

        font-size: 28px;

       }

       .logo2{

        box-sizing: border-box;

        margin: 0px;

        width: 170px;

        font-size: 12px;

        text-align: center;

        padding-right: 15px;

        color: #73864f;

       }

       .lit{

        display: flex;

       }

       .lit2{

        box-sizing: border-box;

        width: 63px;

        height: 70px;

        padding: 23px 0px;

        text-align: center;

        color: gray;

        font-size: 12px;

       }

       .lit2:hover{

        color:#73864f;

       }

       .k{

       width: 100%;

       background-color: white;

       position: sticky;

       top: 0px;

       z-index: 100;

       }

    .list{

        display: flex;

        width: 750px;

        justify-content: space-around;

        box-sizing: border-box;

        padding-left: 150px;

        margin-top: 20px;

        background-color: white;

       

    }

    .imgg{

        width: 20px;

        height: 20px;

        background-image: url(./bar.png);

        background-repeat: no-repeat;

        background-size: contain;

       }

       .list2{

        display: block;

        box-sizing: border-box;

        width: 72px;

        height: 24px;

        text-align: center;

        font-size: 17px;

       }

       .list3{

        display: block;

        box-sizing: border-box;

        width: 90px;

        height: 24px;

        text-align: center;

        font-size: 17px;

       }

       .list4{

        display: block;

        box-sizing: border-box;

        width: 58px;

        height: 24px;

        text-align: center;

        font-size: 17px;

       }

       .list5{

        display: block;

        box-sizing: border-box;

        width: 58px;

        height: 24px;

        text-align: center;

        font-size: 17px;

       }

       .list6{

        display: block;

        box-sizing: border-box;

        width: 41px;

        height: 24px;

        text-align: center;

        font-size: 17px;

       }

       .list7{

        display: block;

        box-sizing: border-box;

        width: 58px;

        height: 24px;

        text-align: center;

        font-size: 17px;

       }

 

   

</style>

<body>

    <div class="title">

        <div class="sale">

           <p class="text">지금 가입하면 3만원 쿠폰팩 지급!</p>

        </div>

        <div class="name">

          <div class="logo">

              <h3 class="logo1">SALADMEAL</h3>

              <p class="logo2">salad & mealkit</p>

          </div>

          <div class="lit">

              <span class="lit2">로그인</span>

              <span class="lit2">회원가입</span>

              <span class="lit2">주문내역</span>

              <span class="lit2">고객센터</span>

          </div>

        </div>

        <div class="k">

         <div class="list">

            <span class="imgg"></span>

            <span class="list2">카테고리</span>

            <span class="list3">샐드밀소개</span>

            <span class="list4">베스트</span>

            <span class="list5">샐러드</span>

            <span class="list6">포케</span>

            <span class="list7">이벤트</span>

         </div>

        </div></p>

<p><P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

<P>1</P>

    </div></p>

<p></body>

</html></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

aiai1505150
1년 전

감사합니다 !! 문제가 해결되었어요 ㅠㅠ 그럼 부모 태그에  height을 정의 안 해도 해당 요소에 sticky 위치와 z-index 만 정의하면 작동  되는 걸까요..?

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인