如何在不使用隐藏溢出的情况下将边框添加到与边框半径完美匹配的 table 列
How do i add border to the table column that matches the border radius perfectly without using overflow hidden
我正在尝试在下图中实现此设计,作为 table 的第一个 td 上的边框或框阴影。
最重要的是我不能使用隐藏的溢出,因为它会弄乱其中的所有下拉菜单。
我尝试了使用 boxshadow、border 的不同方法,但无法准确切入重点。
这是截图,它使用了 box-shadow 但它并没有完全反映上图的设计。
.wrapper {
background-color: #f1f4f8;
height: 100vh;
}
.table {
border-collapse: separate;
border-spacing: 1px 2px;
border: none;
}
.table td,
.table th {
white-space: nowrap;
border: none !important;
}
.table thead th {
border: none;
padding: 7.5px 10px;
background-color: #f1f4f8;
z-index: 1;
}
.table td {
padding: 10px;
height: 50px;
background-color: #fff;
}
.table td:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.table td:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
.table tbody tr:hover td:first-child {
position: relative;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
box-shadow: inset 2px 0px 0px blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.10.2/umd/popper.min.js" integrity="sha512-nnzkI2u2Dy6HMnzMIkh7CPd1KX445z38XIu4jG1jGw7x5tSL3VBjE44dY4ihMU1ijAQV930SPM12cCFrB18sVw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<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/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="wrapper">
<div class="container">
<table class="table">
<thead>
<th>
Items
</th>
<th>
Price
</th>
<th>
Quantity
</th>
</thead>
<tbody>
<tr>
<td>
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
<button type="button" class="btn btn-secondary">1</button>
<button type="button" class="btn btn-secondary">2</button>
<div class="btn-group" role="group">
<button id="btnGroupDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</div>
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
</tbody>
</table>
</div>
</div>
我可以用这种技术实现设计,但是 overflow: hidden;
如下面的代码片段所示,但是 overflow: hidden
;会弄乱我在 table 列中的其他下拉内容。这是使用伪选择器的样子。
.wrapper {
background-color: #f1f4f8;
height: 100vh;
}
.table {
border-collapse: separate;
border-spacing: 1px 2px;
border: none;
}
.table td,
.table th {
white-space: nowrap;
border: none !important;
}
.table thead th {
border: none;
padding: 7.5px 10px;
background-color: #f1f4f8;
z-index: 1;
}
.table td {
padding: 10px;
height: 50px;
background-color: #fff;
}
.table td:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
position: relative;
overflow:hidden;
}
.table td:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
.table tbody tr:hover td:first-child::after {
width: 2px;
height: 100%;
background-color: #2c66ee;
position: absolute;
left: 0;
content: "";
top: 0;
bottom: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<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/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="wrapper">
<div class="container">
<table class="table">
<thead>
<th>
Items
</th>
<th>
Price
</th>
<th>
Quantity
</th>
</thead>
<tbody>
<tr>
<td>
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
<button type="button" class="btn btn-secondary">1</button>
<button type="button" class="btn btn-secondary">2</button>
<div class="btn-group" role="group">
<button id="btnGroupDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</div>
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
</tbody>
</table>
</div>
</div>
有什么方法可以在不使用 overflow: hidden
的情况下实现这一点?
谢谢。
我会使用线性渐变(Amaury Hanser 也提到过)并使用 css 变量来处理悬停时的偏移量
td:first-child {
background: linear-gradient(
to right,
#2c66ee var(--marker, 0),
#fff 0
);
}
tr:hover td:first-child {
--marker: 2px;
}
我正在尝试在下图中实现此设计,作为 table 的第一个 td 上的边框或框阴影。 最重要的是我不能使用隐藏的溢出,因为它会弄乱其中的所有下拉菜单。
我尝试了使用 boxshadow、border 的不同方法,但无法准确切入重点。 这是截图,它使用了 box-shadow 但它并没有完全反映上图的设计。
.wrapper {
background-color: #f1f4f8;
height: 100vh;
}
.table {
border-collapse: separate;
border-spacing: 1px 2px;
border: none;
}
.table td,
.table th {
white-space: nowrap;
border: none !important;
}
.table thead th {
border: none;
padding: 7.5px 10px;
background-color: #f1f4f8;
z-index: 1;
}
.table td {
padding: 10px;
height: 50px;
background-color: #fff;
}
.table td:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.table td:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
.table tbody tr:hover td:first-child {
position: relative;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
box-shadow: inset 2px 0px 0px blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.10.2/umd/popper.min.js" integrity="sha512-nnzkI2u2Dy6HMnzMIkh7CPd1KX445z38XIu4jG1jGw7x5tSL3VBjE44dY4ihMU1ijAQV930SPM12cCFrB18sVw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<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/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="wrapper">
<div class="container">
<table class="table">
<thead>
<th>
Items
</th>
<th>
Price
</th>
<th>
Quantity
</th>
</thead>
<tbody>
<tr>
<td>
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
<button type="button" class="btn btn-secondary">1</button>
<button type="button" class="btn btn-secondary">2</button>
<div class="btn-group" role="group">
<button id="btnGroupDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</div>
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
</tbody>
</table>
</div>
</div>
我可以用这种技术实现设计,但是 overflow: hidden;
如下面的代码片段所示,但是 overflow: hidden
;会弄乱我在 table 列中的其他下拉内容。这是使用伪选择器的样子。
.wrapper {
background-color: #f1f4f8;
height: 100vh;
}
.table {
border-collapse: separate;
border-spacing: 1px 2px;
border: none;
}
.table td,
.table th {
white-space: nowrap;
border: none !important;
}
.table thead th {
border: none;
padding: 7.5px 10px;
background-color: #f1f4f8;
z-index: 1;
}
.table td {
padding: 10px;
height: 50px;
background-color: #fff;
}
.table td:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
position: relative;
overflow:hidden;
}
.table td:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
.table tbody tr:hover td:first-child::after {
width: 2px;
height: 100%;
background-color: #2c66ee;
position: absolute;
left: 0;
content: "";
top: 0;
bottom: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<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/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="wrapper">
<div class="container">
<table class="table">
<thead>
<th>
Items
</th>
<th>
Price
</th>
<th>
Quantity
</th>
</thead>
<tbody>
<tr>
<td>
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
<button type="button" class="btn btn-secondary">1</button>
<button type="button" class="btn btn-secondary">2</button>
<div class="btn-group" role="group">
<button id="btnGroupDrop1" type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</div>
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
<tr>
<td>
Chocolates
</td>
<td>
0
</td>
<td>
3
</td>
</tr>
</tbody>
</table>
</div>
</div>
有什么方法可以在不使用 overflow: hidden
的情况下实现这一点?
谢谢。
我会使用线性渐变(Amaury Hanser 也提到过)并使用 css 变量来处理悬停时的偏移量
td:first-child {
background: linear-gradient(
to right,
#2c66ee var(--marker, 0),
#fff 0
);
}
tr:hover td:first-child {
--marker: 2px;
}