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

안녕하세요. 메뉴관련 클릭시 색상 변화 부분 문의 드립니다. 채택완료

커스텀웹 1년 전 조회 1,170

안녕하세요. css를 보고 있는데 잘안되서 혹시 도움을 주실수 있을까 문의 드립니다.

 

.gnb_wrap .depth01 > a:before{content:'';width:100%;height:0px;background:#0b80ed;position:absolute;bottom:0;left:0;}
.gnb_wrap .depth01 > a:after{content:'';width:100%;height:0x;background:#0b80ed;position:absolute;bottom:0;left:0;}
.gnb_wrap .depth01 > a.on:before, .gnb_wrap .depth01 > a:hover:before{height:100%;-webkit-transition:0.2s all ease-in-out;-o-transition:0.2s all ease-in-out;transition:0.2s all ease-in-out;transition-delay:0.1s;}
.gnb_wrap .depth01 > a.on:after, .gnb_wrap .depth01 > a:hover:after{height:5px;-webkit-transition:0.2s all ease-in-out;-o-transition:0.2s all ease-in-out;transition:0.2s all ease-in-out;}

 

마우스 오버시 색상이 파란색으로 변하는데 클릭을 하면 다른색상으로 진한 파랑 으로 유지되게 하고 싶은데 잘되지를 않습니다. 요소를 추가 해야 하는 부분인지 

클릭시 색상이 변화되게 하고 싶은데 도움을 부탁드립니다.

감사합니다.

되지

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

답변 3개

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

.class:active{
    color:red!important;
}

클릭시(마우스누르고 때지 않은상태)면 위처럼 하면 :active로 하시면됩니다. 클릭 후 해당 페이지 이동 후 계속 상태를 유지하고 싶으신거면 php변수랑 연계해서 별도로 클래스를 줘야합니다

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

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

s
sinbi Expert
1년 전

클릭 순간만 색깔 변하게 하는 거면 :active 이용하면 되는데,

클릭 후 계속 유지되게 하려면 JS나 PHP로 URL 주소 중 일부 고유 파라미터 유무를 감지해 클래스 등 지정해줘야 할 겁니다. 아미나/나리야/배추빌더 경우 기본으로 이 기능 지원하니, 해당 빌더를 이용하거나 참고해 보세요.

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

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

간단하게 자바스크립트로 적용해 볼 수 있을것 같습니다.

다음을 참고 하셔서 원하시는 형식으로 구현 하시면 되지 않을까 합니다.

 

</p>

<p> <style>

    .gnb_wrap .depth01 > a:before {

      content: '';

      width: 100%;

      height: 0px;

      background: #0b80ed;

      position: absolute;

      bottom: 0;

      left: 0;

    }</p>

<p>    .gnb_wrap .depth01 > a:after {

      content: '';

      width: 100%;

      height: 0px;

      background: #0b80ed;

      position: absolute;

      bottom: 0;

      left: 0;

    }</p>

<p>    .gnb_wrap .depth01 > a.on:before,

    .gnb_wrap .depth01 > a:hover:before {

      height: 100%;

      -webkit-transition: 0.2s all ease-in-out;

      -o-transition: 0.2s all ease-in-out;

      transition: 0.2s all ease-in-out;

      transition-delay: 0.1s;

    }</p>

<p>    .gnb_wrap .depth01 > a.on:after,

    .gnb_wrap .depth01 > a:hover:after {

      height: 5px;

      -webkit-transition: 0.2s all ease-in-out;

      -o-transition: 0.2s all ease-in-out;

      transition: 0.2s all ease-in-out;

    }

  </style>

  <script src="<a href="https://code.jquery.com/jquery-3.6.4.min.js"></script>" target="_blank" rel="noopener noreferrer">https://code.jquery.com/jquery-3.6.4.min.js"></script></a>

  <script>

    $(document).ready(function () {

      $(".gnb_wrap .depth01 > a").click(function () {

        // 클릭 시 .on 클래스 토글

        $(this).toggleClass("on");

      });

    });

  </script></p>

<p>

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

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

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

로그인