You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

导航栏样式问题求助:背景未铺满+菜单位置错误

导航栏问题解决方案

问题描述

  • 导航栏背景未完全铺满页面宽度
  • Home等导航按钮未显示在右侧

修改后的完整CSS代码

@import url('https://fonts.googleapis.com/css2?family=League+Spartan:wght@100;200;300;400;500;600;700;800;900&display=swap');
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Spartan', sans-serif;
}

h1 {
    font-size: 50px;
    line-height:64px;
    color: black;
}

h2 {
    font-size: 46px;
    line-height:54px;
    color: black;
}

h4 {
    font-size: 20px;
    color: black;
}

h6 {
    font-weight: 700;
    font-size: 12px;
}

p {
    font-size: 16px;
    color: #465b52;
    margin: 15px 0 20px 0;
}

.section-p1 {
    padding: 40px 80px;
}

.section-m1 {
    margin: 40px 0;
}

body{
    width: 100%;
}


/* Header Start */

#header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 80px;
    background-color: burlywood;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.06);
    width: 100%;
}

#navbar{
    display:flex;
    align-items: center;
    justify-content: center;
}

#navbar li{
    list-style: none;
    padding: 0 20px;
}

#navbar li a{
    text-decoration: none;
    color: #000;
    transition: all 0.3s ease 0s;
}

#navbar li a:hover {
    color: brown;
}

关键修改说明

  • 背景铺满宽度修复:

    1. 把body的width从100px改为100%,让页面主体占满浏览器宽度
    2. 给#header设置width: 100%;,确保导航栏容器本身宽度铺满页面
  • 导航按钮居右修复:

    1. 将#header的justify-content: centre改为justify-content: space-between,让logo和导航容器分别靠向左右两端
    2. 修正拼写错误:把align-items: centre和justify-content: centre里的英式拼写centre改为美式正确拼写center
  • 额外优化:给导航链接添加text-decoration: none去掉默认下划线,设置color: #000统一默认文字颜色,提升整体视觉效果

内容的提问来源于stack exchange,提问作者sushma jain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 12:57:36