简体   繁体   English

CSS下划线菜单

[英]CSS Underline Menu

I admit I am a no coder and I need to get this look for my menu: 我承认我是一名无编码员,我需要为菜单添加以下外观: 在此处输入图片说明

I do want to animate it on hover and I want the effect to remain after it's clicked (you can see example of the animation in the CSS code I have attached). 我确实想在悬停时为其设置动画,并且希望在单击后保持效果(您可以在所附的CSS代码中看到动画的示例)。 So I managed to get the bottom border, but I do want to create some space between the border and text and I also wanna get the top border. 所以我设法获得了下边框,但是我确实想在边框和文本之间创建一些空间,我也想获得上边框。 For some reason it didn't work for me. 由于某种原因,它对我不起作用。

Here's my code so far: 到目前为止,这是我的代码:

 ol, ul { list-style: none; } li { display: inline-block; vertical-align: middle; } a:hover, a:focus, a:active { color: #61f6ff; text-decoration: none; } a::before { content: ''; display: block; position: absolute; bottom: 3px; left: 0; height: 3px; width: 100%; background-color: #61f6ff; transform-origin: right top; transform: scale(0, 1); transition: color 0.1s,transform 0.2s ease-out; } a:active::before { background-color: #61f6ff; } a:hover::before, a:focus::before { transform-origin: left top; transform: scale(1, 1); } 
 <ul> <li class="item"><a href="#">Homepage</a></li> <li class="item"><a href="#">About Us</a></li> <li class="item"><a href="#">Our Services</a></li> <li class="item"><a href="#">Costumers</a></li> <li class="item"><a href="#">Contact Us</a></li> </ul> 

Assign border-top and border-bottom to anchor links and animate them via css3 transitions to achieve fade in like animation. 分配border-top和border-bottom以锚定链接,并通过css3过渡对其进行动画处理,以实现像动画一样的淡入淡出。 You can also play with padding to achieve more space between border and text. 您也可以使用填充来获得边框和文本之间的更多空间。 Working code below. 下面的工作代码。

 ol, ul { list-style: none; } li { display: inline-block; vertical-align: middle; } a { text-decoration: none; color: #0B1B70; -webkit-transition: border 200ms ease-out; -moz-transition: border 200ms ease-out; -o-transition: border 200ms ease-out; transition: border 200ms ease-out; border-bottom: 1px solid transparent; border-top: 1px solid transparent; padding: 2px; } a:hover, a:focus, a:active { border-bottom: 1px solid #61f6ff; border-top: 1px solid #61f6ff; } 
 <nav> <ul> <li class="item"> <a href="#">Homepage</a> </li> <li class="item"> <a href="#">About Us</a> </li> <li class="item"> <a href="#">Our Services</a> </li> <li class="item"> <a href="#">Costumers</a> </li> <li class="item"> <a href="#">Contact Us</a> </li> </ul> </nav> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM