【发布时间】:2022-02-03 19:58:25
【问题描述】:
问题 1: 谁能告诉我如何使这个搜索框响应?因为当我尝试更改屏幕宽度时,按钮会出现在输入字段下方。
问题 2: 如何在不使用 display: flex 的情况下将 div class="search_box" div 水平居中; justify-content: center; 在父 div 中?
这是我的代码 sn-p:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Search Box</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: rgb(233, 175, 98);
}
.parent{
display: flex;
justify-content: center;
/*See the question number 2*/
}
.search_box{
background-color: white;
width: 465px;
height: 50px;
border-radius: 4px;
margin-top: 50px;
}
.search_box_items{
border: none;
border-radius: 4px;
}
input{
width: 370px;
height: 50px;
padding-left: 10px;
}
button{
width: 85px;
height: 43px;
color: white;
background-color: rgb(84, 152, 230);
}
button:hover{
background-color: rgb(70, 147, 235);
}
button:active{
background-color: rgb(33, 129, 240);
}
</style>
</head>
<body>
<div class="parent">
<div class="search_box">
<input class="search_box_items" type="text" placeholder="Search...">
<button class="search_box_items" type="submit">Search</button>
</div>
</div>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
</body>
</html>
【问题讨论】:
标签: html css responsive-design bootstrap-5