[英]Top navigation bar hover underline effect
For a project, I need to create the following navigation bar:对于一个项目,我需要创建以下导航栏:
Like you can see the buttons of this navigation bar have mainly two specificities:就像你可以看到这个导航栏的按钮主要有两个特点:
hover
or active
the navigation buttons, there is a 'grey underline' that takes the screen full width.hover
或active
导航按钮时,会有一个“灰色下划线”占据整个屏幕宽度。hover
or active
a button, the corresponding button's color and underline become blue.hover
或active
一个按钮时,相应按钮的颜色和下划线变为蓝色。 To be honest, I'm completely lost about how to implement these two specificities.老实说,我完全不知道如何实现这两个特性。
At first, I tried to style the by default underline
of the .nav-button
( text-decoration-offset
) and also their border-bottom
, but I always have the two following problems:起初,我尝试设置
.nav-button
( text-decoration-offset
) 的默认underline
以及它们的border-bottom
,但我总是遇到以下两个问题:
underline
/ border-bottom
don't take the full width of the screen.underline
/ border-bottom
没有占据屏幕的整个宽度。hover
/ active
effect on the line begins and end.hover
/ active
效果的开始和结束位置。 Then I tried to style the border-bottom
of #nav-menu
, but I again faced two problems:然后我尝试设置
#nav-menu
的border-bottom
样式,但我又遇到了两个问题:
hover
/ active
effect on the line begins and end.hover
/ 线路上的active
效果开始和结束的位置。#nav-menu
is the container of my buttons, it means that when I hover
or active
on one of them, I can't affect their parent, in our case #nav-menu
( Stack Overflow ). #nav-menu
是我的按钮的容器,这意味着当我hover
或在其中一个上active
时,我不能影响它们的父级,在我们的例子中是#nav-menu
( Stack Overflow )。 And since I'm allowed to use only HTML and CSS , this second method can't be used. Here is my code:这是我的代码:
#nav-menu { display: flex; flex-flow: row wrap; justify-content: space-evenly; }.nav-button { color: black; font-size: 18px; padding-top: 16px; text-decoration: none; cursor: pointer; }.nav-button:hover { color: #0065FC; }
<nav id="nav-menu"> <a class="nav-button">Accommodations</a> <a class="nav-button">Activities</a> </nav>
I really thank in advance anybody who will be kind enough to try to help me:D.我真的提前感谢任何愿意帮助我的人:D。
You have to add flex: 1
to get full width for .nav-button
您必须添加
flex: 1
以获得.nav-button
全宽
#nav-menu { display: flex; flex-flow: row wrap; justify-content: space-evenly; }.nav-button { color: black; font-size: 18px; padding: 16px; text-decoration: none; cursor: pointer; border-bottom: 2px solid #f2f2f2; flex: 1; text-align: center }.nav-button:hover { color: #0065FC; border-bottom: 2px solid #3465fc; }
<nav id="nav-menu"> <a class="nav-button">Accommodations</a> <a class="nav-button">Activities</a> </nav>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.