简体   繁体   English

hover (CSS) 上的移动边框

[英]Moving border on hover (CSS)

I love the buttons on this site - https://veronicaromney.com/我喜欢这个网站上的按钮 - https://veronicaromney.com/

I tried copying the CSS from the site but I am not making it work right.我尝试从站点复制 CSS 但我没有让它正常工作。

I do use Elementor, I added the code to the theme (for the button) and then the ID to the button, but what I got is that the button block (entire block) got the CSS and did nothing on hover.我确实使用 Elementor,我将代码添加到主题(用于按钮),然后将 ID 添加到按钮,但我得到的是按钮块(整个块)获得了 CSS 并且在 hover 上什么也没做。

Can you help me build these buttons?你能帮我制作这些按钮吗?

Here is the code I have so far that pretty much isn't working for me.这是我到目前为止的代码,几乎不适合我。

.mmb-btn { -webkit-text-size-adjust: 100%;
    box-sizing: border-box;
    text-decoration: none;
    text-rendering: optimizeLegibility;
    position: relative;
    color: #fff;
    border: 0 none;
    box-shadow: 0 4px 13px rgba(0, 0, 0, 0.1);
    background-color: #e4b067;
    display: inline-block;
    transition: none 0s ease 0s;
    text-align: inherit;
    line-height: 24px;
    border-width: 0px;
    margin: 0 auto;
    padding: 12px 33px 11px;
    letter-spacing: 4px;
    font-weight: 400;
    font-size: 14px;
  }
.mmb-btn:before {
    border: 1px solid #000;
    top: 7px;
    left: 7px;
}
.mmb-btn::after {
    bottom: 0;
    right: 0;
}
.mmb-btn:before, .mmb-btn:after {
    box-sizing: inherit;
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    transition-property: all;
    transition-duration: 0.25s;
    transition-timing-function: ease;
    transition-delay: 0s;
}

 .mmb-btn { -webkit-text-size-adjust: 100%; box-sizing: border-box; text-decoration: none; text-rendering: optimizeLegibility; position: relative; color: #fff; border: 0 none; box-shadow: 0 4px 13px rgba(0, 0, 0, 0.1); background-color: #e4b067; display: inline-block; transition: none 0s ease 0s; text-align: inherit; line-height: 24px; border-width: 0px; margin: 0 auto; padding: 12px 33px 11px; letter-spacing: 4px; font-weight: 400; font-size: 14px; }.mmb-btn:before { border: 1px solid #000; top: 7px; left: 7px; }.mmb-btn::after { bottom: 0; right: 0; }.mmb-btn:before, .mmb-btn:after { box-sizing: inherit; content: ''; position: absolute; width: 100%; height: 100%; transition-property: all; transition-duration: 0.25s; transition-timing-function: ease; transition-delay: 0s; }.mmb-btn:hover:before, .mmb-btn:hover:after { top: 0; left: 0; transition: all 0.25s ease; }
 <a id="start-here-btn" class="mmb-btn alignright" href="/contact/"> GET STARTED </a>

You were missing .mmb-btn:hover:before, .mmb-btn:hover:after .您缺少.mmb-btn:hover:before, .mmb-btn:hover:after

You have to add only the :hover pseudo class.您只需添加:hover伪 class。

.mmb-btn:hover::before, .mmb-btn:hover::after {
    top: 0;
    left: 0;
    transition: all 0.25s ease;
}

 .mmb-btn { -webkit-text-size-adjust: 100%; box-sizing: border-box; text-decoration: none; text-rendering: optimizeLegibility; position: relative; color: #fff; border: 0 none; box-shadow: 0 4px 13px rgba(0, 0, 0, 0.1); background-color: #e4b067; display: inline-block; transition: none 0s ease 0s; text-align: inherit; line-height: 24px; border-width: 0px; margin: 0 auto; padding: 12px 33px 11px; letter-spacing: 4px; font-weight: 400; font-size: 14px; }.mmb-btn:before { border: 1px solid #000; top: 7px; left: 7px; }.mmb-btn::after { bottom: 0; right: 0; }.mmb-btn:before, .mmb-btn:after { box-sizing: inherit; content: ''; position: absolute; width: 100%; height: 100%; transition-property: all; transition-duration: 0.25s; transition-timing-function: ease; transition-delay: 0s; }.mmb-btn:hover::before, .mmb-btn:hover::after { top: 0; left: 0; transition: all 0.25s ease; }
 <a href="https://stackoverflow.com" id="start-here-btn" class="mmb-btn aalignright" href="/contact/"> GET STARTED </a>

A quickie because why not.匆匆忙忙,因为为什么不呢。 I suggest using transform instead of changing the position as it's more dom fluid and semantically cleaner.我建议使用transform而不是更改 position,因为它更流畅且语义更清晰。

Also remember to apply pointer-events: none to the pseudo element so you don't get the spazzy behavior when someone hovers the border outside of the button like you see on the other answers provided.还要记住将pointer-events: none应用于伪元素,这样当有人将边框悬停在按钮外部时,您不会像您在提供的其他答案中看到的那样出现令人毛骨悚然的行为。

 .fancy-btn { padding: .5rem 1.5rem; background-color: #eee; position: relative; transition: background-color.5s ease; }.fancy-btn:after { content: ''; display: block; pointer-events: none; border: red 1px solid; position: absolute; width: 100%; height: 100%; top: 0; left: 0; transform: translate(1rem,1rem); transition: transform.25s ease; }.fancy-btn:hover { background-color: yellow; }.fancy-btn:hover:after { top: 0; left: 0; border-color: green; transform: translate(0,0); } body { height: 90vh; display: flex; align-items: center; justify-content: center; }
 <a class="fancy-btn">HEY I AM A BUTTON, YAY</a>

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

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