我甚至不确定这是否可能!
我正在尝试动画化围绕着居中文本链接的填充量。当您单击文本链接时,填充会从20%更改为100% - 这一点有效 :)
使用CSS使文本居中。
我遇到的问题是当我悬停在链接上时,文本链接会晃动/闪烁。我猜测这是因为CSS也在尝试重新调整文本以适应额外的填充,这导致了悬停时的闪烁。
我还在其中包括了一个 CodePen 链接,展示了代码的效果 - https://codepen.io/rolandxp30/pen/oNqZoom 我想不到其他方法了吗?有没有一种稳定或居中文本的方法或者实现相同动画效果的另一种方法?
先感谢您的帮助,
诚挚问候,
Brian
我正在尝试动画化围绕着居中文本链接的填充量。当您单击文本链接时,填充会从20%更改为100% - 这一点有效 :)
使用CSS使文本居中。
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
我正在使用过渡属性来动画化填充位。
transition-property: padding;
transition-duration: .5s;
transition-timing-function: ease-in-out;
如果代码有点笨重,我很抱歉 - 这是我在这里使用的完整代码:
#homePanel {
width: 300px;
height: 300px;
position: relative;
overflow: hidden;
}
#homePanel img {
width: 100%;
filter: grayscale(1%);
transition-property: opacity;
transition-duration: .4s;
transition-timing-function: ease-in-out;
height: auto;
}
#panelLink h3 a {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-weight: bold;
text-transform: uppercase;
text-align: center;
letter-spacing: 2px;
color: #ffffff;
background-color: rgba(0, 0, 0, 0.6);
padding: 20%;
transition-property: padding;
transition-duration: .5s;
transition-timing-function: ease-in-out;
}
#panelLink h3 a {
color: #fff;
text-decoration: none;
}
#panelLink h3 a:hover {
color: #fff;
padding: 100%;
}
<div id="homePanel">
<div id="panelLink">
<a href="https://www.google.co.uk/"><img src="https://www.landscapia.co.uk/wp-content/uploads/2022/03/landscapia-design.jpg" alt="Landscapia Design" width="600" height="600" class="img-responsive" /></a>
<h3><a href="https://www.google.co.uk/">Design</a></h3>
</div>
</div>
我还在其中包括了一个 CodePen 链接,展示了代码的效果 - https://codepen.io/rolandxp30/pen/oNqZoom 我想不到其他方法了吗?有没有一种稳定或居中文本的方法或者实现相同动画效果的另一种方法?
先感谢您的帮助,
诚挚问候,
Brian
transform: scale(5)
。 - CBroe