【问题标题】:animating button makes adjacent elements move动画按钮使相邻元素移动
【发布时间】:2021-01-15 14:16:15
【问题描述】:



我有两个在悬停时动画的按钮。
每当我将鼠标悬停在每个按钮上时,该按钮都会推开相邻的元素。
如果您查看下面的 GIF,悬停按钮会推开另一个按钮并放大其父按钮。

Hovering on Button GIF

HTML:我有两个按部分嵌套的按钮。

<section id="section2">
        <a href="" id="firstBtn" class="button btnPush commonBtn">홈</a>
        <a href="" id="secondBtn" class="button btnPush commonBtn">마이페이지</a>
</section>

CSS1:对于部分,我给了它一个边框,以便清楚地看到该区域。

#section2 {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid blue;
}

CSS2:用于按钮

.commonBtn {
    font-family: 'GmarketSansBold';
    text-decoration: none;
    color: black;
    letter-spacing: 2px;
    font-size: 20px;
    display: none;
}

.commonBtn.button {
    position: absolute;
    width: 190px;
    padding: 0;
    margin: 10px 20px 10px 0;
    font-weight: 600;
    text-align: center;
    line-height: 50px;
    color: #4B4D52;
    border-radius: 5px;
    transition: all 0.2s;
}

.commonBtn.btnPush {
    background: #FFFFFF;
    box-shadow: 0px 4px 20px rgba(104, 109, 224, 0.5);
    border-radius: 50px;
}

.btnPush:hover {
    margin-top: 15px;
    margin-bottom: 5px;
    border: rgba(104, 109, 224, 0.5) 3px solid;
}

.commonBtn.btnPush:hover {
    box-shadow: 0px 0px 0px 0px #007144;
}

包含相同动画按钮的其他页面也会发生同样的情况。

我在 S/O 上搜索并尝试了所有答案,但没有任何帮助。
有没有办法防止按钮推开其他不使用“位置:绝对”的元素? ?

+) 编辑

Structure of the file

【问题讨论】:

  • 您能否提供包含该部分的html?
  • 已将您的代码上传到 JSFIDDLE,因为我无法重现您的结果,所以仍然缺少一些东西 - jsfiddle.net/9ejLnpgo

标签: javascript html css


【解决方案1】:

我稍微改变了过渡,但试试这个:

#section2 {
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #0000fc;
}

.commonBtn {
  font-family: 'GmarketSansBold';
  text-decoration: none;
  color: black;
  letter-spacing: 2px;
  font-size: 20px;
}

.commonBtn.button {
  width: 190px;
  padding: 0;
  margin: 10px 20px 10px 0;
  font-weight: 600;
  text-align: center;
  line-height: 50px;
  color: #4B4D52;
  border-radius: 5px;
  display: inline-block;
  transition-duration: 0.3s;
  transition-property: transform;
  -webkit-tap-highlight-color: transparent;
  transform: translateZ(0);
  box-shadow: 0 0 1px transparent;
}

.commonBtn.btnPush {
  background: #FFFFFF;
  box-shadow: 0px 4px 20px rgba(104, 109, 224, 0.5);
  border-radius: 50px;
}

.btnPush:hover {
  transform: scale(0.9);
}

.commonBtn.btnPush:hover {
  transform: scale(0.9);
}
<section id="section2">
  <a href="" id="firstBtn" class="button btnPush commonBtn">홈</a>
  <a href="" id="secondBtn" class="button btnPush commonBtn">마이페이지</a>
</section>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多