gpt4 book ai didi

html - 为什么这个链接悬停效果是从中间开始而不是左边呢?

转载 作者:太空狗 更新时间:2023-10-29 15:58:35 25 4
gpt4 key购买 nike

我不明白为什么在下面的代码中,链接悬停效果从中间开始,而不是从左到右。有人可以解释为什么会这样吗?

.orange-link {
color: orange;
position: relative;
text-decoration: none;
}

.orange-link:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
background: orange;
bottom: 0;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}

.orange-link:hover:before,
.orange-link:focus:before {
transform: scaleX(1);
}
<p>Visit the official rules <a class="orange-link" href="#">here</a> on how to send in a write-in entry.</p>

最佳答案

这是因为 CSS 转换的默认原点是元素的中心。

"By default it is at the center of the element and can be moved. It is used by several transforms, like rotations, scaling or skewing, that need a specific point as a parameter." — https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transforms/Using_CSS_transforms

线条横跨整个宽度,但缩放到 0(从中心开始)。然后,悬停时,线条会按比例缩小到原来的全宽。

关于html - 为什么这个链接悬停效果是从中间开始而不是左边呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56636559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com