拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 悬停时移动边框(CSS)

悬停时移动边框(CSS)

白鹭 - 2022-02-17 2106 0 0

我喜欢这个网站上的按钮 - https://veronicaromney.com/

我尝试从该站点复制 CSS,但无法使其正常作业。

我确实使用 Elementor,我将代码添加到主题(用于按钮),然后将 ID 添加到按钮,但我得到的是按钮块(整个块)获得了 CSS,并且在悬停时什么也没做。

你能帮我制作这些按钮吗?

这是我到目前为止的代码,几乎不适合我。

.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;
}

uj5u.com热心网友回复:

.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>

你失踪了.mmb-btn:hover:before, .mmb-btn:hover:after

uj5u.com热心网友回复:

匆匆忙忙,因为为什么不呢。我建议使用transform而不是更改位置,因为它更流畅且语意更清晰。

还要记住应用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>

uj5u.com热心网友回复:

您只需添加:hover伪类。

.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>

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *