gpt4 book ai didi

css - 如何实现这种布局?表格标题未与内容对齐,每行的内容也未垂直对齐

转载 作者:行者123 更新时间:2023-11-28 02:21:18 25 4
gpt4 key购买 nike

我正在尝试实现这种布局:

picture of desired output

  • 左侧的类型列比右侧的其他 2 项占用的宽度大得多,这是因为类型和描述可能很大。
  • 此外,每个元素的类型和描述应与数量选择菜单和小计内容垂直对齐。

我正在使用 Bootstrap ,但我是初学者,我正在尝试使用表格组件实现此布局。我不知道将表格组件用于此布局是否是更正确的方法或面板或其他一些东西。

我得到的布局是这样的:https://jsfiddle.net/bcvm3ap2/ , 但表格标题与内容不对齐,每行的内容也未垂直对齐。

你知道怎么修吗?还有如果表格是这种布局的正确方法?

html:

<div class="row no-gutters bg-white">
<div class="col-12 col-md-8 px-4 pb-4">
<table class="table table-responsive-sm border">
<thead>
<tr class="d-flex justify-content-between">
<th scope="col" class="mr-auto">Type</th>
<th scope="col">Quantity</th>
<th scope="col">Subtotal</th>
</tr>
</thead>
<tbody>
<tr>
<td class="">
<span class="text-heading-blue font-weight-semi-bold">Type1</span>
<small class="font-weight-light d-block">Description</small>
</td>
<td><select class="form-control font-weight-normal text-gray" id="exampleFormControlSelect1">
<option selected class="selected">0</option>
<option>1</option>
<option>2</option>
</select>
</td>
<td>0</td>
</tr>
<tr>
<td class="">
<span class="text-heading-blue font-weight-semi-bold">Type2</span>
<small class="font-weight-light d-block">Description</small>
</td>
<td><select class="form-control font-weight-normal text-gray" id="exampleFormControlSelect1">
<option selected class="selected">2</option>
<option>1</option>
<option>2</option>
</select>
</td>
<td>2</td>
</tr>

</tbody>
</table>
</div>
</div>

面板也不起作用:https://jsfiddle.net/jdpr21qw/1/标题与内容不符。

最佳答案

试试这个代码,它会给你你想要的布局。

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="row no-gutters bg-white">
<div class="col-12 col-md-8 px-4 pb-4">
<table class="table table-responsive-sm table-bordered">
<thead class='text-center'>
<tr class="text-center ">
<th scope="col" class="mr-auto">Type</th>
<th scope="col">Quantity</th>
<th scope="col">Subtotal</th>
</tr>
</thead>
<tbody >
<tr >
<td class="">
<span class="text-heading-blue font-weight-semi-bold">Type1</span>
<br/><small class="font-weight-light d-block">Description</small>
</td>
<td><select class="form-control font-weight-normal text-gray" id="exampleFormControlSelect1">
<option selected class="selected">0</option>
<option>1</option>
<option>2</option>
</select>
</td>
<td>0</td>
</tr>
<tr>
<td class="">
<span class="text-heading-blue font-weight-semi-bold">Type2</span>
<br/><small class="font-weight-light d-block">Description</small>
</td>
<td><select class="form-control font-weight-normal text-gray" id="exampleFormControlSelect1">
<option selected class="selected">2</option>
<option>1</option>
<option>2</option>
</select>
</td>
<td>2</td>
</tr>

</tbody>
</table>
</div>
</div>

</body>
</html>

关于css - 如何实现这种布局?表格标题未与内容对齐,每行的内容也未垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48192516/

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