首先,我有一个很大的<div class="content">,它包含<table>,我想要的是:
<table>,只是<tr>:背景颜色变化(没关系),但是内容需要保持边框半径(现在->不行,这是我的问题)。如何使显示的<div class=content">边界半径(现在tr正在覆盖它,边界半径在悬停时消失)
下面是一个简单的脚本(当悬停=相同宽度、相同边框半径时,黄色必须与灰色颜色相同)
.content{
width:100%;
height:auto;
border-radius:10px;
background-color:gray;
}
table{
width:100%;
cursor:pointer;
}
tr{
width:100%;
border-radius:10px !important;
}
table tr:hover{
background-color:gold;
border-radius:10px;
}<div class="content">
<table>
<tr>
<td>hello</td>
<td>world</td>
</tr>
</table>
</div>
发布于 2016-07-18 09:23:53
需要将border-radius应用于td元素。
使用:first-child和:last-child选择器来应用边框半径。
.content {
width: 100%;
height: auto;
border-radius: 10px;
background-color: gray;
}
table {
width: 100%;
cursor: pointer;
}
tr {
width: 100%;
border-radius: 10px !important;
}
table tr:hover {
background-color: gold;
border-radius: 10px;
}
table tr:hover td:first-child {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
table tr:hover td:last-child {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}<div class="content">
<table>
<tr>
<td>hello</td>
<td>world</td>
</tr>
</table>
</div>
发布于 2016-07-18 10:22:39
您需要将border-radius应用于td标记,而不是tr标记。假设表中有多个行,每个行包含多个单元格,则需要将border-radius设置为四个不同的单元格:
以下是您将如何做到的:
table{
background:gray;
border-radius:10px;
width:100%;
}
tr:hover>td{
background:gold;
}
tr:first-child>td:first-child{
border-top-left-radius:10px;
}
tr:first-child>td:last-child{
border-top-right-radius:10px;
}
tr:last-child>td:first-child{
border-bottom-left-radius:10px;
}
tr:last-child>td:last-child{
border-bottom-right-radius:10px;
}<table>
<tbody>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
</tr>
<tr>
<td>Lorem</td>
<td>Ipsum</td>
<td>Dolor</td>
</tr>
</tbody>
</table>
发布于 2016-07-18 09:37:50
您还需要border-radius on td,这就是为什么这个颜色超过了tr的半径
我把border-top-left-radius和border-bottom-left-radius放在第一个td上,把border-top-right-radius和border-bottom-right-radius放在最后一个td上
如果有帮助请告诉我
.content{
width:100%;
height:auto;
border-radius:10px;
background-color:gray;
}
table{
width:100%;
cursor:pointer;
}
tr{
width:100%;
border-radius:10px !important;
}
td:last-child {
-webkit-border-top-right-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-topright: 10px;
-moz-border-radius-bottomright: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
td:first-child{
-webkit-border-top-left-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-moz-border-radius-topleft: 10px;
-moz-border-radius-bottomleft: 10px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
table tr:hover{
background-color:gold;
border-radius:10px;
}<div class="content">
<table>
<tr>
<td>hello</td>
<td>world</td>
</tr>
</table>
</div>
https://stackoverflow.com/questions/38432931
复制相似问题