gpt4 book ai didi

html - 如何使填充不向下移动其他元素?

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:57 24 4
gpt4 key购买 nike

我正在尝试制作一排三个按钮。其中一个按钮有一个 :hover 属性,这使得它的 margin-top 增加了。这看起来像这样:

button {
position: relative;
height: 45px;
width: 150px;
margin: 10px 8px;
padding: 5px 5px;
font-weight: 700;
font-size: 15px;
letter-spacing: 2px;
color: #383736;
border: 2px #383736 solid;
border-radius: 4px;
text-transform: uppercase;
outline: 0;
overflow:hidden;
background: none;
z-index: 1;
cursor: pointer;
transition: 0.15s;
}

button:hover {
color: whitesmoke;
}

.btn:hover:before {
right: 0;
}

.btn:before {
content: "";
position: absolute;
background: #383736;
bottom: 0;
left: 0;
right: 100%;
top: 0;
z-index: -1;
transition: right .15s;
}

.btn2:hover:before {
top: 0;
}

.btn2:before {
content: "";
position: absolute;
background: #383736;
bottom: 0;
left: 0;
top: 100%;
right: 0;
z-index: -1;
transition: top .15s;
}

.continue {
border-color: lime;
color: lime;
}

.continue:before {
content: "";
background-color: lime;
}

.continue:hover {
padding-top: 20px;
}

.continue:hover:before {
content: "\2192";
}
<button class = "btn">
HOVER
</button>

<button class = "btn2">
HOVER
</button>

<button class = "btn continue">
CONTINUE
</button>

当您悬停第三个按钮时,它的 padding-top 会发生变化,因此其他两个按钮会向下移动。我该怎么做才能使它具有相同的效果,只是其他两个按钮不动?

最佳答案

在按钮上添加vertical-align: top(默认是baseline)就足够了

button {
position: relative;
height: 45px;
width: 150px;
margin: 10px 8px;
padding: 5px 5px;
font-weight: 700;
font-size: 15px;
letter-spacing: 2px;
color: #383736;
border: 2px #383736 solid;
border-radius: 4px;
text-transform: uppercase;
outline: 0;
overflow:hidden;
background: none;
z-index: 1;
cursor: pointer;
transition: 0.15s;
vertical-align: top;
}

button:hover {
color: whitesmoke;
}

.btn:hover:before {
right: 0;
}

.btn:before {
content: "";
position: absolute;
background: #383736;
bottom: 0;
left: 0;
right: 100%;
top: 0;
z-index: -1;
transition: right .15s;
}

.btn2:hover:before {
top: 0;
}

.btn2:before {
content: "";
position: absolute;
background: #383736;
bottom: 0;
left: 0;
top: 100%;
right: 0;
z-index: -1;
transition: top .15s;
}

.continue {
border-color: lime;
color: lime;
}

.continue:before {
content: "";
background-color: lime;
}

.continue:hover {
padding-top: 20px;
}

.continue:hover:before {
content: "\2192";
}
<button class = "btn">
HOVER
</button>

<button class = "btn2">
HOVER
</button>

<button class = "btn continue">
CONTINUE
</button>

关于html - 如何使填充不向下移动其他元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49013572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com