【发布时间】:2019-03-25 08:38:28
【问题描述】:
我正在尝试设计一个带有自动完成下拉菜单的搜索栏,例如 Google 的。但是,下拉菜单没有搜索栏那么宽
它可以在 MICROSOFT EDGE 上运行,但不能在 GOOGLE CHROME 上运行
我尝试将宽度更改为自动和设备宽度,但我发现自动完成下拉菜单的宽度没有变化
.input-group-btn{ 宽度:自动;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta name = "viewport" content = "width=device-width, inital-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
body{
background:#202a3f;
}
.container{
margin-top:200px;
}
.glyphicon-search{
font-size:20px;
}
.btn-default{
background: orange;
width:100px;
padding:12.5px;
}
.form-control{
padding:25px;
font-size:20px;
}
.input-group-btn{
width:auto;
}
}
.navbar {
overflow: hidden;
background-color: #333;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.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;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
}
</style>
</head>
<body>
<div class="navbar" >
<a href="#home" >Home</a>
<a href="#favorites">Favorites</a>
<div class = "dropdown">
<button class="dropbtn">Genre
<i class = "fa fa-caret-down"></i>
</button>
<div class ="dropdown-content">
<a href="#">Drama</a>
</div>
</div>
</div>
<div class="container">
<form action="/action_page.php">
<div class = "input-group">
<input type="text" class = "form-control" placeholder="Search" name="search">
<div class ="input-group-btn ">
<button type="submit" class = "btn btn-default">
<i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</body>
</html>
当我保持宽度自动或设备宽度时,下拉菜单非常小,但是,如果宽度是一些巨大的实际数字,如 1000 像素或 30000 像素,则整个搜索栏的宽度会缩小,然后下拉菜单的宽度为搜索栏。
【问题讨论】:
标签: html css twitter-bootstrap bootstrap-4