html - CSS 宽度不适用于 HTML 选择标签
问题描述
我正在学习 Bootstrap v5.0。我正在尝试select
使用 CSS 调整标签的大小,width
但它不起作用。我也尝试了 Bootstrap .col
,但它也无法正常工作。
我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Input</title>
</head>
<body>
<div class="alert bg-light">
<div class="container">
<h4 class="alert-heading">Custom file input</h4>
<hr>
<div class="input-group">
<select class="form-select" style="width: 40px;">
<option value="1">C</option>
<option value="2">C++</option>
<option value="3">Java</option>
<option value="4">Python</option>
<option value="5">JavaScript</option>
</select>
<input type="file" class="form-control" multiple>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
</body>
</html>
如何调整此select
标签的大小?
如果可以使用引导程序,那么请建议我使用引导程序或 CSS 的解决方案。
解决方案
将您的替换width
为max-width
,您的选择标签将按预期运行。
Bootstrap 实际上添加了一个样式规则,使宽度select
非常流畅。
select {
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
}
width
不能覆盖这些样式规则,这就是您应该使用的原因max-width
推荐阅读
- function - 如何执行已存储在变量中的 Lisp 程序?
- html - HTML 和 CSS 中的导航栏选项卡
- html - 使用 R 从动态网页中提取文本
- c# - 如何用受保护的构造函数和私有属性设置填充对象?
- php - 在 WooCommerce 付款完成时将订单状态设置为自定义状态
- javascript - Zoom 如何能够从浏览器启动自身?
- python - 如何使用 Python 将一个字典中的值随机分配给另一个字典
- docker - Multistage docker build: stat 报告 NVIDIA 文件不存在,但它确实存在
- r - 如何在 sparklyr 中随时间计算唯一值(给出示例)?
- node.js - 如何使用单个读取流,进行多次转换并使用 Sharp 分别写入一个单独的流?