我正在尝试制作一排三个按钮。其中一个按钮具有:hover
属性,使其边缘增加。这看起来像这样:
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>
&#13;
当您悬停第三个按钮时,它的填充顶部会发生变化,因此其他两个按钮会向下移动。除了其他两个按钮不移动之外,我能做些什么来使它具有相同的效果?
答案 0 :(得分:4)
将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";
}
&#13;
<button class = "btn">
HOVER
</button>
<button class = "btn2">
HOVER
</button>
<button class = "btn continue">
CONTINUE
</button>
&#13;