Bootstrap mobile menu icon change to x close

后端 未结 8 1439
一向
一向 2021-02-05 13:54

EDIT

@zim answer uses 2020 CSS to easily solve the issue and better applies to Bootstrap 4.

The original question and selected answer are still

8条回答
  •  被撕碎了的回忆
    2021-02-05 14:44

    The below code helps you to solve this issue.

    Html:

    Mobile Navigation menu using css and jquery

    css:

    .btn {
    background-color: #ffd200;
    color: #00174f;
    display: inline-block;
    text-decoration: none;
    padding: 13px 30px;
    margin: 30px 0 0 0;
    border-radius: 3px;
    font-weight: bold;
    }
    .btn:hover {
    background-color: #fff;
    }
    .btn--transition {
    -webkit-transition: -webkit-transform 0.2s;
    -webkit-transition: all 200ms ease-in-out;
    transition: all 200ms ease-in-out;
    }
    :focus {
    outline: none;
    }
    .icons {
    margin: 50px 0;
    }
    .icon {
    margin: 0 30px 0 0;
    }
    
    .icon {
    background-color: #ff3000;
    border: 0;
    height: 79px;
    width: 79px;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    }
    .icon span {
    display: block;
    height: 5px;
    width: 33px;
    background-color: #ffffff;
    border-radius: 2px;
    position: absolute;
    left: 23px;
    -webkit-transition: -webkit-transform 0.3s;
    -webkit-transition: all 300ms ease-in-out;
    transition: all 300ms ease-in-out;
    }
    .icon span:first-child {
    top: 28px;
    }
    .icon span:nth-child(2) {
    top: 37px;
    }
    .icon span:last-child {
    top: 46px;
    }
    .icon--active span:first-child {
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
    position: absolute;
    top: 37px;
    }
    .icon--active span:last-child {
    -webkit-transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    transform: rotate(-45deg);
    position: absolute;
    top: 37px;
    }
    .icon--active span:nth-child(2) {
    opacity: 0;
    }
    .icon--button {
    border-radius: 10px;
    }
    .icon-transition {
    -webkit-transition: -webkit-transform 0.3s;
    -webkit-transition: all 300ms ease-in-out;
    transition: all 300ms ease-in-out;
    }
    

    javascript

    
    

    This snippets is used to change the mobile icon to close icon on click the button. Demo

提交回复
热议问题