html - 平滑的按钮过渡

标签 html css

将鼠标悬停在按钮上后,按钮所在的扩展容器出现问题。它在振动,这让它看起来真的很糟糕。理想情况下仅使用 CSS 即可解决问题,因为我也将这些样式用于表单的提交按钮。

关于如何改进它有什么建议吗?

Link to codepen

<div class="button-container">
  <a class="button" href="#">Text</a>
</div>


.button-container {
background: red;
}
.button {
background:#fff;
font-size:1em; 
padding:18px 26px; 
display:inline-block; 
margin:5px; 
border-radius:6px; 
border:solid rgba(0,0,0,0.2); 
border-width:1px 1px 5px; 
box-shadow:0 5px 0 rgba(0,0,0,0.1), inset 0 0 2px rgba(255,255,255,0.3); 
cursor:pointer; 
user-select:none; 
transition:0.4s ease; 
min-width: 10em;
margin-top: 3px;
}

.button:hover {
margin-top: 0;; 
box-shadow:0 6px 0 rgba(0,0,0,0.1), inset 0 0 1px rgba(255,255,255,0.4); 
border-bottom-width:8px; 
margin-top: 0px;
}

.button:active {  
box-shadow:0 2px 0 rgba(0,0,0,0.1), inset 0 0 5px rgba(255,255,255,0.4); 
border-bottom-width:2px; 
transition:0.1s ease;
margin-top: 7px;
}

最佳答案

如果您将按钮定位为绝对位置,它不会影响容器大小:

.button {
  position: absolute;
}
.button-container {
  height: 68px; /* ensure the container still has the same size */
}

关于html - 平滑的按钮过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37699267/

相关文章:

javascript - 高级网页转换

CSS 元素在 Safari 中低于预期位置

html - 为什么这个 SCSS 选择器不起作用

javascript - TypeaHead BootStrap 不起作用

javascript - 加速改变 div 元素颜色的 JavaScript 函数构造 'led display'

html - 等宽字体中字符的字体大小和宽度之间有什么依赖关系?

html - 为什么我的下拉菜单不以最大宽度为中心?

css:定位元素在顶部与另一个元素而不是底部齐平

html - 如何将容器与主体中心对齐?

html - div定位不正确