【问题标题】:Navigation bar links stacking on each other导航栏链接相互堆叠
【发布时间】:2021-11-10 06:01:05
【问题描述】:

我正在尝试为我的学校项目构建我的网站,并尝试使用 flexbox 制作导航栏。其他一切工作正常,但由于某种原因,Tietoa、Usein ja Yhteyttä 的链接相互堆叠,我无法让它工作。我已经尝试在 nav 和 ul 链接中添加 display flex 和 content justify 但它仍然不起作用

<!DOCTYPE html>
    <head>
        <meta charset="utf-8"
        
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="style.css"
    </head>
    <body>
        <header>
            <img class="logo" src="logo.png" alt="logo">
            <nav>
                <ul class="nav_links">
                    <li><a href="#">Tietoa</a></li>
                    <li><a href="#">Usein</a></li>
                    <li><a href="#">Yhteydet</a></li>
                </ul>
            </nav>
            <a class="cta" href="#"><button>yhteyttä</button></a>
        </header>
    </body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap');
body {
    background-color: #F5F5F5;
    color: black;
}
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: 1px solid red;
    
}

li, a, button {
    font-family: "Montserrat", sans-serif;
    font-weight: 500;
    font-size: 16px;
    color: black;
    text-decoration: none;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 10%;
    background-color: white;
    box-shadow: 0px 2px 5px lightgray;
}

.logo {
    cursor: pointer;
    width: 100px;
    height: 100px;
}

.nav__links {
    list-style: none;
    display: inline-block;
}

.nav__links li {
    display: inline-block;
    padding: 0px 20px;
}

.nav__links li a {
    transition: all 0.3s ease 0s;
}

.nav__links li a:hover {
    color: #0088a9
}

button {
    padding: 9px 25px;
    background-color: rgba(0, 136, 169, 1);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease 0s;
}

button:hover {
    background-color: rgba(0, 136, 169, 0.8);
}

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    您在 html 和 css 中的类名不同,请修复它们:

    @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap');
    body {
        background-color: #F5F5F5;
        color: black;
    }
    * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        outline: 1px solid red;
        
    }
    
    li, a, button {
        font-family: "Montserrat", sans-serif;
        font-weight: 500;
        font-size: 16px;
        color: black;
        text-decoration: none;
    }
    
    header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30px 10%;
        background-color: white;
        box-shadow: 0px 2px 5px lightgray;
    }
    
    .logo {
        cursor: pointer;
        width: 100px;
        height: 100px;
    }
    
    .nav_links {
        list-style: none;
        display: flex;
        flex-direction:row;
    }
    
    .nav_links li {
        display:block;
        padding: 0px 20px;
    }
    
    .nav__links li a {
        transition: all 0.3s ease 0s;
    }
    
    .nav__links li a:hover {
        color: #0088a9
    }
    
    button {
        padding: 9px 25px;
        background-color: rgba(0, 136, 169, 1);
        border: none;
        border-radius: 50px;
        cursor: pointer;
        transition: all 0.3s ease 0s;
    }
    
    button:hover {
        background-color: rgba(0, 136, 169, 0.8);
    }
    <!DOCTYPE html>
        <head>
            <meta charset="utf-8"
            
            <meta name="description" content="">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link rel="stylesheet" href="style.css"
        </head>
        <body>
            <header>
                <img class="logo" src="logo.png" alt="logo">
                <nav>
                    <ul class="nav_links">
                        <li><a href="#">Tietoa</a></li>
                        <li><a href="#">Usein</a></li>
                        <li><a href="#">Yhteydet</a></li>
                    </ul>
                </nav>
                <a class="cta" href="#"><button>yhteyttä</button></a>
            </header>
        </body>
    </html>

    【讨论】:

      猜你喜欢
      • 2018-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多