我的问题源于this
我想在4列中水平对齐复选框
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TEST</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
</head>
<body>
<div class="row">
<div class="col-md-12">
<form action='' method="POST" novalidate>
<div>
<div>
<label>GROUP 1</label>
<div style="display: table;">
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_1" name="0_1">
<label for="0_1">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_2" name="0_2">
<label for="0_2">CK1_2</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_3</label>
</div>
</div>
</div>
<br/>
<div>
<label>GROUP 2</label>
<div style="display: table;">
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="1_1" name="1_1">
<label for="1_1">CK2_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="1_2" name="1_2">
<label for="1_2">CK2_2</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="1_3" name="1_3">
<label for="1_3">CK2_3</label>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
问题是,当我有10个以上的复选框时,它们会与标签正确对齐,但对于较少的复选框,正如你在上面的片段中看到的,渲染并不和谐
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TEST</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
</head>
<body>
<div class="row">
<div class="col-md-12">
<form action='' method="POST" novalidate>
<div>
<div>
<label>GROUP 1</label>
<div style="display: table;">
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_1" name="0_1">
<label for="0_1">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_2" name="0_2">
<label for="0_2">CK1_2</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_3</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="0_3" name="0_3">
<label for="0_3">CK1_1</label>
</div>
</div>
</div>
<div>
<label>GROUP 2</label>
<div style="display: table;">
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="1_1" name="1_1">
<label for="1_1">CK2_1</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="1_2" name="1_2">
<label for="1_2">CK2_2</label>
</div>
<div style="width:25%; display: inline-table; margin: 5px 0;">
<input type="checkbox" id="1_3" name="1_3">
<label for="1_3">CK2_3</label>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
2条答案
按热度按时间bxfogqkk1#
您可以使用网格显示。
如果这不是你要找的,告诉我。我很乐意帮忙
flvlnr442#
可以使用Flexbox。当
flex-direction
为column
时,您可以限制容器的高度(这里为max-height: 30vh
),项目(<label>
)将开始形成列。但要控制列数、高度和“项目”的数量真的很难。您也可以将项目排成一行。这是一个非常灵活的,你不需要指定一个高度。如果每个
<label>
的宽度都是25%,那么你就有4列。