gpt4 book ai didi

html - 选择选项菜单中的自动换行

转载 作者:太空宇宙 更新时间:2023-11-04 05:37:30 25 4
gpt4 key购买 nike

如何将文本包装在选项菜单中?我想要选项值跟随选择器的宽度。短文本效果很好,但不适用于长文本。

我在这个论坛里尝试了很多东西,但没有任何效果。我正在使用 bootstrap classes 并且还没有额外的 css

选择带有短文本的选项菜单

enter image description here

选择带有长文本的选项菜单

enter image description here

  <div class="form-group col-md-5">
<label for="programstrategis_id">Program Strategis</label>
<select id="programstrategis_id"
class="selectpicker data-content form-control @error ('programstrategis_id') is-invalid @enderror"
name="programstrategis_id">
<option selected disabled>--silahkan pilih program strategis berikut--</option>
@foreach ($programstrategis_id as $dataprogramstrategis)
<option value="{{ $dataprogramstrategis->id }}">{{$dataprogramstrategis->program_strategis}}
</option>

@endforeach
</select>
@error('programstrategis_id')
<div class="invalid-feedback">
{{ $message }}
</div>
@enderror
</div>

<div class="form-group col-md-5">
<label for="sasaran_id">Sasaran</label>
<select id="sasaran_id"
class="selectpicker form-control @error ('sasaran_id') is-invalid @enderror"
name="sasaran_id">
<option selected disabled>--silahkan pilih sasaran berikut--</option>
@foreach ($sasaran_id as $datasasaran)
<option value="{{ $datasasaran->id }}">{{$datasasaran->sasaran}}</option>
@endforeach
</select>
@error('sasaran_id')
<div class="invalid-feedback">
{{ $message }}
</div>
@enderror
</div>

最佳答案

I'm using bootstrap classes and no additional css yet.

由于您使用的是 Bootstrap ,因此可以使用 <div> 创建下拉列表或 <a>标记而不是 <select> .将文本包裹在里面更容易。

您可以为 dropdown-menu 设置默认宽度类和更新 white-space所有子项的属性 .dropdown-item .

.dropdown-menu {
width: 170px;
}

.dropdown-menu .dropdown-item {
white-space: normal;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here Something else here Something else here Something else here Something else here Something else here Something else here</a>
</div>
</div>

关于html - 选择选项菜单中的自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59508496/

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