我有一个按钮,悬停将改变它的宽度从50px到300px,.But,它只是这样做的一侧(无论是积极的或消极的),我希望它改变它的宽度为300px与150px在任何一边。
.container-2 {
width: 300px;
vertical-align: middle;
white-space: nowrap;
position: relative;
}
.container-2 #search {
width: 50px;
-webkit-transition: width .55s ease-in-out;
-moz-transition: widtg .55s ease-in-out;
-ms-transition: width .55s ease-in-out;
-o-transition: width .55s ease-in-out;
}
.container-2:hover #search {
outline: none;
width: 300px;
-webkit-transition-delay: 0.2s;
-moz-transition-delay: 0.2s;
transition-delay: 0.2s;
}<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="box">
<div class="container-2">
<span class="icon">
<i class="fa fa-search"></i>
</span>
<input type="search" id="search" placeholder="Search Wikipedia" />
</div>
</div>
</body>
</html>
发布于 2016-07-22 17:33:54
这是一个使用两种不同实现的小提琴。第一个是原始的居中技巧。第二个是使用flex-box。如果你可以逃脱惩罚,使用flex。
下面是没有使用flexbox的CSS:
#container-1 {
text-align: center;
}
#button-1 {
margin: auto;
}这就是flexbox:
#container-2 {
display: flex;
justify-content: center;
}https://stackoverflow.com/questions/38522066
复制相似问题