gpt4 book ai didi

html - 响应式选择菜单布局

转载 作者:行者123 更新时间:2023-11-28 02:20:37 27 4
gpt4 key购买 nike

我正在使用 Bootstrap ,我希望在 md、lg 和 xml 屏幕中有 4 个水平相邻的选择菜单,并且“搜索”与 4 个选择垂直对齐:

enter image description here

然后在较小的设备中,我希望在水平方向上有 4 个选择菜单,而不是彼此相邻的 4 个选择菜单,我希望在上方有 2 个选择菜单,在下方有 2 个选择菜单,例如:

enter image description here

但是我没有成功实现这个,你知道如何实现吗?

工作示例:http://jsfiddle.net/wqdqfuud/

第一点有效,4 个选择菜单水平相邻,但问题是一些文本被隐藏,因为选择菜单尺寸不够大。其他 2 点我没有成功实现它们。

html:

<body>
<div class="container py-4">
<div class="row mb-3 mb-md-0">
<div class="col">
<h1 class="text-center d-md-none my-0 h5 text-heading-blue font-weight-bold">Search</h1>
</div>
</div>
<div class="row">
<div class="col d-flex justify-content-center align-items-center">
<h1 class="d-none d-md-block w-100 mr-auto my-0 h5 text-heading-blue font-weight-bold">Search</h1>
<form class="mr-2">
<select class="form-control font-weight-normal text-gray" id="">
<option selected class="selected">Order By P1</option>
<option>i2</option>
</select>
</form>
<form class="mr-2">
<select class="form-control font-weight-normal text-gray" id="">
<option selected class="selected">Order By P2</option>
<option>i1</option>
</select>
</form>
<form class="mr-2">
<select class="form-control font-weight-normal text-gray" id="">
<option selected class="selected">Order By P3</option>
<option>i2</option>
</select>
</form>
<form>
<select class="form-control font-weight-normal text-gray" id="">
<option selected class="selected">Order by P4</option>
<option>i1</option>
</select>
</form>
</div>
</div>
</div>
</body>

最佳答案

您非常接近,只是您的结构出现了一些错误,使用 Grid 框架而不是 d-flex 可以更好地实现这些错误。以下是我将如何实现您想要的结果:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>

<div class="container">
<div class="row justify-content-center align-items-center">
<div class="col-12 col-md-6">
<h1 class="text-md-center">Search</h1>
</div>

<div class="col-12 col-md-6">
<div class="row">
<div class="col-6 col-md-3 mb-4 mb-md-0">
<form>
<select class="custom-select form-control" id="i1">
<option selected>Order By 1</option>
<option>i2</option>
<option >i2</option>
</select>
</form>
</div>

<div class="col-6 col-md-3 mb-4 mb-md-0">
<form>
<select class="custom-select form-control" id="i2">
<option selected>Order By 2</option>
<option>i2</option>
<option >i2</option>
</select>
</form>
</div>

<div class="col-6 col-md-3">
<form>
<select class="custom-select form-control" id="i3">
<option selected>Order By 3</option>
<option>i2</option>
<option >i2</option>
</select>
</form>
</div>

<div class="col-6 col-md-3">
<form>
<select class="custom-select form-control" id="i4">
<option selected>Order By 4</option>
<option>i2</option>
<option >i2</option>
</select>
</form>
</div>
</div>

</div>
</div>
</div>

可以在此处查看 Bootply 示例:https://www.bootply.com/6VbSYN0Rlj

此示例依赖于响应速度更快的类,例如让“搜索”在大屏幕上居中对齐,在小屏幕上居中对齐。它还利用网格框架(带有嵌入式 row 来帮助排列所有内容。我们需要在前两个 select 选项和最后两个选项之间添加边距的地方适当的响应 margin 等级。

关于html - 响应式选择菜单布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48233153/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com