css 如何解决超链接问题的HTML网站与侧边栏?

wbgh16ku  于 2022-12-27  发布在  其他
关注(0)|答案(2)|浏览(131)

所以我正在为自己创建一个网站,在尝试超链接时遇到了一些问题。我知道我需要将整个文本 Package 在锚元素中,但是,尽管这样做了,并且我的联系人页面已经准备好了,我还是无法点击超链接。下面附上的是我一直在使用的主要HTML代码和CSS代码,以及为了说明我在做什么。

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Fire Sans', sans-serif;
    text-decoration: none;
    list-style: none;
    color: #FFF;
}

.app{
    display: flex;
    min-height: 100vh;
}

.sidebar{
    flex: 1 1 0;
    max-width: 300px;
    padding: 2rem 1rem;
    background-color: #051427;
    
}

.sidebar h3{
    color: #707793;
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.sidebar .menu{
    margin: 0 -1rem;
}

.sidebar .menu .menu-item{
    display: block;
    padding: 1rem;
    color: #FFF;
    text-decoration: none;
    transition: 0.2s linear;
}

.sidebar .menu .menu-item:hover,
.sidebar .menu .menu-item.is-active{
    color #6f6d72;
    border-right: 5px solid #6f6d72;
}

.content{
    flex: 1 1 0;
    padding: 2rem;
}

.content h1{
    color: #D8BFD8;
    font-size: 2.5rem;
    font-family: papyrus;
    margin-bottom: 1rem;
}

.content p{
    color: #C8C8C8;
    font-family: papyrus;
}

.menu-toggle{
    display: none;
    position: fixed;
    top: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 99px;
    background-color: #051427;
    cursor: pointer;
}

.hamburger{
    position: relative;
    top: calc(50% - 2px);
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
}

.hamburger > span,
.hamburger > span::before,
.hamburger > span::after{
    display: block;
    position: absolute;
    width: 100%;
    height: 4px;
    border-radius: 99px;
    background-color: #FFF;
    transition-duration: .25s;
}

.hamburger > span::before{
    content: '';
    top:-8px;
}

.hamburger > span:after{
    content: '';
    top: 8px;
}

.menu-toggle.is-active .hamburger > span{
    transform: rotate(45deg);
}

.menu-toggle.is-active .hamburger > span::before{
    top: 0;
    transform: rotate(0deg);
}

.menu-toggle.is-active .hamburger > span::after{
    top: 0;
    transform: rotate(90deg);
}

@media (max-width: 1024px){
    .sidebar{
        max-width: 200px;
    }
}

@media (max-width: 768px){
    .menu-toggle{
        display: block;
    }

    .content{
        padding-top: 8rem;
    }

    .sidebar{
        position: fixed;
        top: 0;
        left: -300px;
        height: 100vh;
        width: 100%;
        max-width: 300px;
        transition: 0.2s linear
    }

    .sidebar.is-active{
        left: 0;
    }
}

body{
    font-family: papyrus;
    background-image: url(AstroImg.jpg);
    background-size: cover;
    background-position: center;
}
<!DOCTYPE html>
<html>
    <head>
    
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content= "IE-edge">
    <meta name= "viewport" content="width=device-width, initial-scale=1.0">
    
    <link rel="stylesheet" type="text/css" href="main.css">
    <script src="https://kit.fontawesome.com/4767153995.js" crossorigin="anonymous"></script>

    <title> MAP | Astrophotography </title>
    </head>
        <body>      
        <div class="app">
            
            <div class= "menu-toggle">
                <div class= "hamburger">
                    <span></span>
                </div>
            </div>

            <aside class="sidebar">
                <h3>Menu</h3>
                
                <nav class= "menu">
                    <a href="#" class="menu-item is-active"><i class="fa-solid fa-house"></i>  Home</a>
                    <a href="#" class="menu-item"><i class="fa-solid fa-user"></i>   About Me</a>                   <a href="#" class="menu-item"><i class="fa solid fa-gears"></i>  My Equipment</a>
                    <a href="#" class="menu-item"><i class="fa-solid fa-star"></i>  Image Gallery</a>
                    <a href=" contact.html"><a href="#" class="menu-item"><i class="fa-regular fa-address-book"></i>Contact</a></a>
                </nav>

            </aside>

            <main class="content">
                <h1> Mapping Astronomical Points </h1>
                <p>Your guide to the sky</p>

            </main>

        </div>

        <script>
            const menu_toggle = document.querySelector('.menu-toggle');
            const sidebar = document.querySelector('.sidebar');

            menu_toggle.addEventListener('click', () => {
                menu_toggle.classList.toggle('is-active');
                sidebar.classList.toggle('is-active');
            })
        </script>



        </body>
</html>

下面是我正在努力修复的例子。如果我删除class标签,超链接工作正常,但随后它开始扭曲网站的布局,如果我保留class标签,超链接根本不工作。我能做些什么来修复这个问题?任何帮助都是感激的。

<a href=" contact.html"><a href="#" class="menu-item"><i class="fa-regular fa-address-book"></i>Contact</a></a>
iswrvxsc

iswrvxsc1#

移除嵌套锚并将类添加到外部定位点。

<a href="contact.html" class="menu-item"><i class="fa-regular fa-address-book"></i>Contact</a>
zpjtge22

zpjtge222#

更改此行:

<a href=" contact.html"><a href="#" class="menu-item"><i class="fa-regular fa-address-book"></i>Contact</a></a>

用这个:

<a href="contact.html" class="menu-item"><i class="fa-regular fa-address-book"></i>Contact</a>

**解释:**定位标记中不应该有锚标记。

相关问题