RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1539455
Accepted
Elijah_Pris
Elijah_Pris
Asked:2023-09-07 14:47:49 +0000 UTC2023-09-07 14:47:49 +0000 UTC 2023-09-07 14:47:49 +0000 UTC

如何对齐 navbare 中的元素

  • 772

我正在尝试根据 YouTube 上的以下视频制作一个导航栏:https://www.youtube.com/watch? v=a3rofqqrTBE&ab_channel=OnlineTutorials,用于我也从 YouTube 下载的简历(现在我认为很明显,我我是新手,不太明白)

要点是白色元素(指定白色用于对比)又名指示器与所有其他元素一起绘制,但与它们的位置不一致。

在此输入图像描述

在此输入图像描述

这是负责这个动画的代码片段

导航栏.jsx

<div className="Nav_container">
    <div className="logo">
        <img src={LogoGif} alt="my-gif" />
    </div>
    <div className="icons" >
        <ul className="nav_links">
            {navLinks.map((navlink, index) => {
                return <li class="list active" key={index}>
                <div class="indicator"></div>
                <a href={`#${navlink.links}`}>{navlink.icons}
                    <span class="text">{navlink.links}</span>
                </a>
                </li>
            })}
        </ul>
    </div>
</div>

导航栏.scss

.nav_links {
    display: flex;
    list-style: none;
    max-height: 50px;

    li {
        margin-left: 3rem;

        @media screen and (max-width: 800px){
            display: none;
        }
        &:hover {
            .text {
                opacity: 1;
                transform: translateY(-10px); 
                background: rgb(66,66,66);
                padding: 2px 7px;
                border-radius: 12px;
            }
            svg {
                opacity: 1;
                transform: translateY(30px);
            }
            .indicator {
                transform: translateY(30px);
            }
        }
        .indicator {
            top: 0px;
            border: 6px solid rgba(0,0,0,0.0);
            border-radius: 50%;
            position: absolute;
            width: 70px;
            height: 70px;
            background: rgb(29,31,35);
            background-color: #fff;
            transition: 0.4s;
        }
        .indicator::before {
            content: '';
            position: absolute;
            top: 34px;
            left: 58px;
            width: 30px;
            height: 30px;
            background: transparent;
            border-radius: 50%;
            box-shadow: -14px -16px white;
        }
        .indicator::after {
            content: '';
            position: absolute;
            top: 34px;
            left: -30px;
            width: 30px;
            height: 30px;
            background: transparent;
            border-radius: 50%;
            box-shadow: 14px -16px white;
        } 
        a {
            position: relative;
            display: flex;
            align-items: center;
            flex-direction: column;
            width: 100%;
            text-align: center;
            text-decoration: none;
            transition: 0.5s;
            color: #fff;
            text-transform: uppercase;
            font-weight: 100;
            &:hover {
                opacity: 1;
            }
        }
        .text {
            font-size: 0.8em;
            opacity: 0;
            margin-top: -25px;
            transition: 0.5s;
            letter-spacing: 0.1em;
        }
        svg {
            display: block;
            font-size: 2em;
            transition: 0.7s;
        }
    }
}

需要添加什么来移动指示器的位置与其余元素一致(我认为很明显,图标和文本在同一水平上对齐,只有指示器被移动)

html
  • 1 1 个回答
  • 24 Views

1 个回答

  • Voted
  1. Best Answer
    Павел Ериков stand with Russia
    2023-09-08T01:00:35Z2023-09-08T01:00:35Z

    添加width: 70px;到您的li。

    .nav_links {
        ...
        li {
            width: 70px;
            ...
        }
    }
    

    结果: 结果

    Ps我建议你仔细重新观看视频并正确重写样式。正因为如此,我发现了与你的风格不一致的地方之一。您还可以使用浏览器中的开发人员工具。还将.gitignore文件添加到React应用程序所在的文件夹中,至少使用node_modules. 因此,在克隆存储库时,您不必下载所有模块。

    • 1

相关问题

  • 具有非均匀背景的块内的渐变边框

  • 离开页脚

  • 如何将三个字段的数据收集到一封电子邮件中?

  • Html 元素刚从父元素中出来

  • 如何在css中制作这个背景?

  • 如何制作带有斜条纹的背景?

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5