0

Okay, so I was coding my portfolio website. But when I completed coding my responsive navbar, I notice a problem that wasn't supposed to be there as I did everything fine according to me. I have a burger menu. When I click the burger, the navbar slides from the right to left and vice versa. Working perfectly fine. But the problem arises, after pressing the tab key. When I press the tab key on the homepage, it is selecting the navbar which is suppose to be hidden far right. How to fix it?

Here is HTML

<header>
        <div class = 'logo'>
            Logo
        </div>

        <nav>
            <div class = 'burger'>
                <div class="line1"></div>
                <div class="line2"></div>
                <div class="line3"></div>
            </div>

            <ul class = 'nav-links'>
                <li><a href = '#'>Link-1</a></li>
                <li><a href = '#'>Link-2</a></li>
                <li><a href = '#'>Link-3</a></li>
                <li><a href = '#'>Link-4</a></li>
            </ul>
        </nav>
    </header>

Here is SCSS

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
    overflow-x: hidden;
}

header {
    height: 100px;
    width: 100%;
    background: coral;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid white;

.logo {
    font-family: 'Prompt-ExtraLight';
    color: #fff;
    font-size: 1.5rem;
    padding-left: 1rem;
}

nav {
    .burger {
        cursor: pointer;
        padding-right: 1rem;
        position: relative;
        z-index: 1;
        
        div {
            width: 30px;
            height: 3px;
            background: #fff;
            margin: 5px;
            transition: .3s all ease;
        }
    }

    ul {
        height: 100vh;
        width: 100%;
        background: coral;
        position: absolute;
        top: 0;
        right: 0;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        transform: translateX(100%);
        transition: transform 0.3s ease-in;

        li {
            list-style-type: none;
            font-size: 1.5rem;
            font-family: 'Prompt-ExtraLight';
            padding: 1rem 2rem;
            width: 12rem;
            height: auto;
            transition: .2s all ease-in;

            a {
                text-decoration: none;
                color: #fff;
            }
            
            &:hover {
                background: #005a34;
                transform: translateX(10%);
            }
        }
    }

    .nav-links-active {
        transform: translateX(0);
    }

    .toggle .line1 {
        transform: rotate(-45deg) translate(-5px,6px);
    }

    .toggle .line2 {
        opacity: 0;
    }

    .toggle .line3 {
        transform: rotate(45deg) translate(-5px,-6px);
    }
}

Here is JSFiddle

https://jsfiddle.net/nilsbh12/q3fhngeb/5/

DMT
  • 51
  • 2
  • 9

1 Answers1

1

Add tabindex="-1" to your links.

<ul class = 'nav-links'>
  <li><a href = '#'  tabindex="-1">Link-1</a></li>
  <li><a href = '#'  tabindex="-1">Link-2</a></li>
  <li><a href = '#'  tabindex="-1">Link-3</a></li>
  <li><a href = '#'  tabindex="-1">Link-4</a></li>
</ul>

Also you can check this for more options.

Muhammedogz
  • 774
  • 8
  • 21