gpt4 book ai didi

html - HTML/CSS 中的播放按钮对齐问题

转载 作者:行者123 更新时间:2023-11-28 00:42:21 25 4
gpt4 key购买 nike

我在左侧有一个标题,想在右侧添加一个与标题内联的按钮。

当我添加“position:relative: 和 top:400px”时,它会完美地移动按钮。当我添加“left:200px”时,它会再次完美地移动按钮,但是当我悬停时它会将按钮移回页面中心.

我如何阻止它这样做?

我创建了 IMG 图像来具体展示它是如何移动的: https://imgur.com/a/SMLCbmN

** 离开时注意:200px;未添加,按钮不会移动到页面中心。我试过删除“text-algin: center;”连同许多其他想法……但我被卡住了。

这是代码:https://codepen.io/TheGreatEscape/pen/ebYgGO

.container {
width: 100%;
text-align: center;
margin-top: 0vh;
}

.circle {
stroke: #f70f4d;
stroke-dasharray: 650;
stroke-dashoffset: 650;
-webkit-transition: all 0.5s ease-in-out;
opacity: 0.3;
}

.playBut {
position: relative;
top: 400px;
left: 200px;
border: none;
-webkit-transition: all 0.5s ease;
}

.playBut .triangle {
-webkit-transition: all 0.7s ease-in-out;
stroke-dasharray: 240;
stroke-dashoffset: 480;
stroke: #000;
transform: translateY(0);
}

.playBut:hover .triangle {
stroke-dashoffset: 0;
opacity: 1;
stroke: #f70f4d;
animation: nudge 0.7s ease-in-out;
}

@keyframes nudge {
0% {
transform: translateX(0);
}
30% {
transform: translateX(-5px);
}
50% {
transform: translateX(5px);
}
70% {
transform: translateX(-2px);
}
100% {
transform: translateX(0);
}
}

.playBut:hover .circle {
stroke-dashoffset: 0;
opacity: 1;
}
<div class='container'>
<a href='#' class='playBut'>

<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0px" y="0px" width="213.7px" height="213.7px" viewBox="0 0 213.7 213.7" enable-background="new 0 0 213.7 213.7"
xml:space="preserve">

<polygon class='triangle' id="XMLID_18_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
73.5,62.5 148.5,105.8 73.5,149.1 "/>

<circle class='circle' id="XMLID_17_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" cx="106.8" cy="106.8" r="103.3"/>
</svg>


</a>
</div>

最佳答案

如果有帮助,请查看此演示

/*===== PLAY BUTTON ===*/

.container {
width: 100%;
text-align: center;
margin-top: 0vh;
}

.circle {
stroke: #f70f4d;
stroke-dasharray: 650;
stroke-dashoffset: 650;
-webkit-transition: all 0.5s ease-in-out;
opacity: 0.3;
}

.playBut {
/*position: relative;
top:400px;
left:200px;*/
border: none;
-webkit-transition: all 0.5s ease;
}
.playBut .triangle {
-webkit-transition: all 0.7s ease-in-out;
stroke-dasharray: 240;
stroke-dashoffset: 480;
stroke: #000;
transform: translateY(0);
}
.playBut:hover .triangle {
stroke-dashoffset: 0;
opacity: 1;
stroke: #f70f4d;
animation: nudge 0.7s ease-in-out;
}
@keyframes nudge {
0% {
transform: translateX(0);
}
30% {
transform: translateX(-5px);
}
50% {
transform: translateX(5px);
}
70% {
transform: translateX(-2px);
}
100% {
transform: translateX(0);
}
}
.playBut:hover .circle {
stroke-dashoffset: 0;
opacity: 1;
}


h2.title {
font-size: 40px;
margin: 60px 0 0;
display: inline-block;
float: left;
}
<div class='container'>

<h2 class="title">some text</h2>

<a href='#'class='playBut'>

<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In -->
<svg version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
x="0px" y="0px" width="213.7px" height="213.7px" viewBox="0 0 213.7 213.7" enable-background="new 0 0 213.7 213.7"
xml:space="preserve">

<polygon class='triangle' id="XMLID_18_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
73.5,62.5 148.5,105.8 73.5,149.1 "/>

<circle class='circle' id="XMLID_17_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" cx="106.8" cy="106.8" r="103.3"/>
</svg>


</a>
</div>

更新你需要

a.playBut, a.playBut:hover, a.playBut:active, a.playBut:focus {
left: 800px;
right: auto;
}

参见 demo

正常 enter image description here

悬停 enter image description here

关于html - HTML/CSS 中的播放按钮对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53744376/

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