[英]How would I go about creating the hover animation for the nav in this website?
The website is https://ceremonycoffee.com/ . 该网站为https://ceremonycoffee.com/ 。 How do I replicate their nav hover animation with the underline? 如何复制带有下划线的导航悬停动画? I can't really find it in their inspect element. 我在他们的inspect元素中找不到它。 Also, is it made from CSS or Javascript? 另外,它是由CSS还是Javascript制成的? Thank you! 谢谢!
You can do it in full css, see this snippet : 您可以在完整的CSS中执行此操作,请参见以下代码段:
h2 > a { position: relative; color: #000; text-decoration: none; } h2 > a:hover { color: #000; } h2 > a:before { content: ""; position: absolute; width: 100%; height: 2px; bottom: 0; left: 0; background-color: #000; visibility: hidden; -webkit-transform: scaleX(0); transform: scaleX(0); -webkit-transition: all 0.3s ease-in-out 0s; transition: all 0.3s ease-in-out 0s; } h2 > a:hover:before { visibility: visible; -webkit-transform: scaleX(1); transform: scaleX(1); }
<h2><a href="#">My Link</a></h2>
It relies on the ::before
pseudo element. 它依靠::before
伪元素。 You set its horizontal scale to zero, add a transition property so that when hovered it transforms smoothly to the full link scale. 将其水平比例设置为零,添加过渡属性,以便将鼠标悬停时将其平滑转换为完整的链接比例。
Source and explanation : Animating Links Underline 来源和说明: 动画链接下划线
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.