如何在NAV BAR中悬停链接

发布于 2025-02-06 05:15:59 字数 674 浏览 2 评论 0原文

我敢肯定,其他人可能会遇到同样的问题,但我不仅是CSS的新手,英语也不是我的主要语言,因此我真的不知道该如何研究如何解决这个问题。我不知道该怎么称呼这种情况。基本上,在悬停的情况下,文本稍微移动而不是留在其所属的位置。我假设我在桨上做错了什么。但是我知道,可以具有这种“按钮”效果,例如,悬停效果的背景颜色具有该大小,但我真的无法找到解决方案...我已经花了几个小时尝试不同的方法但没有成功。我也不确定我是否适当地设计了链接。有人可以帮忙吗?

这是下面的Navbar CSS代码:

 .nav-items {
    display: flex;
    transform: translateX(0px);
    margin-right: 5%;
    
  }
  
  .nav-items li {
    list-style: none;
    padding: 25px;
  }
  
  .nav-items a {
    color: white;
    text-decoration: none;
    letter-spacing: 1px;
    font-size: 14px;
  }
  
  .nav-items li a:hover {

    background-color:#006aff;
    padding: 20px;
    transition: 0.2s ease-in-out;

  }

I am sure others might have experienced the same problem, but not only am I new to CSS, English is also not my main language, and therefore I don't really know how to go about researching on how to solve this issue. I don't know what to call this situation. Basically, upon hover, the text slightly moves instead of staying where it belongs. I am assuming I am doing something wrong with paddings. But I know that it is possible to have this "button" effect, as in, the background color of the hover effect having that size, but I really can't figure out a solution... I have been hours and hours trying different methods but no success. I am also not sure if I am styling the links properly. Can someone help please?

Here's my navbar CSS code below:

 .nav-items {
    display: flex;
    transform: translateX(0px);
    margin-right: 5%;
    
  }
  
  .nav-items li {
    list-style: none;
    padding: 25px;
  }
  
  .nav-items a {
    color: white;
    text-decoration: none;
    letter-spacing: 1px;
    font-size: 14px;
  }
  
  .nav-items li a:hover {

    background-color:#006aff;
    padding: 20px;
    transition: 0.2s ease-in-out;

  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2025-02-13 05:15:59

如我所见,您正在悬停在悬停状态下添加填充物。

您的代码应该像这样描述的方式,要显示导航项目。

.nav-items a {

   color: white;
   text-decoration: none;
   letter-spacing: 1px;
   font-size: 14px;
   padding: 20px;
   transition: 0.2s ease-in-out;

}

.nav-items li a:hover {
    background-color: #006aff;
}

As I can see you are adding the padding in the hover state.

Your code should be like this the way you have described you want to show the navigation items.

.nav-items a {

   color: white;
   text-decoration: none;
   letter-spacing: 1px;
   font-size: 14px;
   padding: 20px;
   transition: 0.2s ease-in-out;

}

.nav-items li a:hover {
    background-color: #006aff;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文