简体   繁体   English

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

[英]Play Button Alignment Issues in HTML/CSS

I have a header on the left side and want to add a button inline with the header on the right side. 我在左侧有一个标题,想要在标题的右侧添加一个内联按钮。

When I add "position:relative: and top:400px, it moves the button perfectly. When i add "left:200px" it moves the button perfectly again, but when i hover it moves the button back to center of page. 当我添加“ position:relative:”和“ top:400px”时,它完美地移动了按钮。当我添加“ left:200px”时,它又又完美地移动了按钮,但是当我将鼠标悬停时,它又将按钮移动回了页面的中心。

How do i stop it from doing this? 我如何阻止它执行此操作?

i've created IMG images to show specifically how it moves: https://imgur.com/a/SMLCbmN 我已经创建了IMG图像以专门显示其运动方式: https//imgur.com/a/SMLCbmN

**note when left:200px; **注意左:200px; is not added, the button doesn't move to center of page. 未添加,按钮不会移到页面中心。 i've tried removing the "text-algin: center;" 我试过删除“ text-algin:center;” along with a lot of other ideas..but am stuck. 以及许多其他想法..但被卡住了。

Here is the code: https://codepen.io/TheGreatEscape/pen/ebYgGO 这是代码: 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> 

Add position: absolute to your .playBut . 在您的.playBut position: absolute添加position: absolute top and left works only on absolute position. topleft仅适用于绝对位置。

See example here 在这里查看示例

see this demo if it helps 看这个演示是否有帮助

 /*===== 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> 

Update you need 更新您需要的

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

see demo 观看演示

normal 正常 在此处输入图片说明

on hover 悬停时 在此处输入图片说明

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

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