html - 文本框缩小时的按钮对齐 (CSS)
问题描述
好吧,我想做的是,每当我的页面调整大小时,我希望我的文本框旁边的按钮在文本框旁边对齐,这会导致我的文本框相应地缩小或扩大(如下面所示片段)有人可以帮我吗?在此先感谢您的帮助!
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
background-color: transparent;
}
.topnav a {
display: inline-block;
color: black;
padding: 14px 16px;
text-decoration: none;
font-size: 16px;
}
.topnav .icon {
display: none;
}
.dropdown {
float: right;
padding-top: 5px;
}
.hehe {
float: right;
padding-top: 5px;
}
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: black;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.topnav a:hover,
.dropdown:hover .dropbtn {
background-color: transparent;
color: skyblue;
}
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
@media screen and (max-width: 900px) {
.topnav a:not(:nth-child(-n+2)),
.dropdown .dropbtn {
display: none;
}
.topnav a:not(:nth-child(-n+2)),
.hehe {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 900px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {
float: none;
}
.topnav.responsive .hehe {
float: none;
}
.topnav.responsive .dropdown-content {
position: relative;
}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
.topnav.responsive .hehe {
display: block;
width: 100%;
text-align: left;
}
}
.searchFeature {
border: 1px solid #999;
padding: 3px 18px 3px 4px; /* Use the same right padding (18) in jQ! */
border-radius: 3px;
/* transition: background 0.4s; */
width:40%;
position: absolute;
top: 18px;
left: 75px;
}
.test {
position: absolute;
top: 20px;
left: 350px;
}
<div class="topnav" id="myTopnav" ng-controller="searchController">
<a href="#!/index" class="searchba"><img ng-src="" />LOGO</a>
<input type="text" class="searchFeature" ng-model="selected" ng-keyup="$event.keyCode == 13 && searchFunction()" uib-typeahead="value for value in themename | filter:$viewValue | limitTo:7" placeholder="Start your search here..."><button class="test">Test</button>
<div class="hehe">
<a href="">Developer</a>
<a href="">Data Enquiry</a>
</div>
<div class="dropdown">
<button class="dropbtn">Categories <i class="fa fa-caret-down"></i></button>
<div class="dropdown-content" >
<a ng-click="pickCate(x)" ng-repeat="x in selectCate">{{ x }}</a>
</div>
</div>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
</div>
解决方案
.test
从和中删除绝对定位.searchFeature
,然后将它们包装在 flexbox 中。我还建议在输入中添加最小宽度。
HTML:
<div class="search-wrapper">
<input type="text" class="searchFeature" ng-model="selected" ng-keyup="$event.keyCode == 13 && searchFunction()" uib-typeahead="value for value in themename | filter:$viewValue | limitTo:7" placeholder="Start your search here...">
<button class="test">Test</button>
</div>
CSS:
.search-wrapper {
display: flex;
flex-direction: row;
}
.test {}
.searchFeature {
border: 1px solid #999;
padding: 3px 18px 3px 4px; /* Use the same right padding (18) in jQ! */
border-radius: 3px;
/* transition: background 0.4s; */
width:40%;
}
推荐阅读
- python - 对于所有可能的行和列组合,根据它们的相对距离聚合 pandas 数据框的值
- c# - Puppeteer Sharp - js 运行完成后获取 html
- machine-learning - 无法理解 YOLOv4 架构
- ios - 在 Else 块中访问 ObservableObject 时视图不更新
- python - Python 结构模式匹配
- javascript - 如何在视频停止播放后隐藏或淡出 HTML 视频,然后显示下面的 H1 标题标题
- apache-kafka - 为什么Kaka Streams repartition topic的retention.ms默认设置为-1?这不是在重新分区主题中无限保留消息吗?
- php - 尝试发布 Laravel 包时无法找到可发布的资源
- javascript - 如何让 Javascript 循环在开始下一个迭代之前等待现有迭代完成?
- python - 字符识别问题 pytesseract/tesseract-OCR/ 无法识别