【发布时间】:2020-04-26 12:26:29
【问题描述】:
我是整个 CSS 编码的新手,有时我会卡住。我遵循了关于如何制作动画搜索栏的在线教程,使其看起来令人愉悦。我正在为我的学校项目做一个网站,我几乎完成了只是在这里和那里添加了一些位。它是关于从 20 世纪初到今天的技术。
.search-pos {
display: block;
margin-left: auto;
width: 330px;
position: relative;
top: -40px;
}
.search-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-55%, -55%);
background: white;
height: 40px;
border-radius: 60px;
padding: 10px;
}
.search-box:hover>.search-txt {
width: 240px;
padding: 0 4px;
}
.search-box:hover>.search-btn {
background: white;
padding: 10px;
}
.search-btn {
color: black;
float: center;
width: 30px;
height: 30px;
border-radius: 80%;
background: white;
display: flex;
justify-content: center;
align-items: center;
transition: 0.4s;
}
.search-txt {
border: none;
background: none;
outline: none;
float: left;
padding: 0;
color: white;
font-size: 14px;
transition: 0.4s;
line-height: 40px;
width: 0px;
}
<div class="search-pos">
<div class="search-box">
<input class="search-txt" type="text" name="" placeholder="Type to search">
<a class="search-btn" href="#">
<i class="fas fa-search"></i>
</a>
</div>
</div>
我尝试过更改填充、定位甚至高度,但似乎没有任何效果。我想我需要添加另一行代码,但我不确定它会是什么。
会发生什么:
正如您所见,按钮并没有像应有的那样留在栏本身内。
【问题讨论】:
-
您能解释一下哪里出了问题以及它应该是什么样子吗?还需要用float不能用flex吗?
-
请分享您的标头 HTML 代码。
标签: javascript html css web