我需要在单元格中添加一个正三角形。
如何实现?
我尝试在 span 中添加图标,但是效果不对。
<span style="position: relative;float:right;top:-30px;">@Html.ImageContent("triangle_bonus.png", "")</span>
我需要在单元格中添加一个正三角形。
如何实现?
我尝试在 span 中添加图标,但是效果不对。
<span style="position: relative;float:right;top:-30px;">@Html.ImageContent("triangle_bonus.png", "")</span>
使用 CSS三角形:
您基本上拥有一个高度为0,宽度为0的元素,并使用边框来构建三角形。因为边框之间的线(例如,顶部和左侧之间)是对角线,所以您可以使用它创建漂亮的、纯色的三角形!
<table border="1">
<tr>
<td class="note">Triangle!</td>
<td>No Triangle!</td>
</tr>
</table>
td {
padding: 20px;
}
.note {
position: relative;
}
.note:after { /* Magic Happens Here!!! */
content: "";
position: absolute;
top: 0;
right: 0;
width: 0;
height: 0;
display: block;
border-left: 20px solid transparent;
border-bottom: 20px solid transparent;
border-top: 20px solid #f00;
} /* </magic> */
<span>
,而不是依赖于:after
。通过谷歌发现这个问题并遇到了一些问题,尽管原贴已经过时,我还是会在这里添加。
Madara的答案在大多数浏览器中有效,并且在所有浏览器中在表格之外的任何地方都有效。但是如评论所述,此示例在Firefox中不起作用。
有一个非常老的Bugzilla票与position:absolute;
在<td>
元素中无法工作。
主要解决方案是添加内部的<div>
:
HTML:
<table border="1">
<tr>
<td><div class="note">Triangle!</div></td>
<td>No Triangle!</td>
</tr>
</table>
CSS:
td .note {
padding: 20px;
}
我发现只有在<td>
为空时才能实现没有内部<div>
,这可能并不有用。
.arrow-right-1 {
position: absolute;
top: -1px;
right: -5px;
float: right;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid red;
transform: rotate(45deg);
}
td {
border: solid 1px blue;
width: 160px;
height: 100px;
/* padding: 0px !important; */
/* vertical-align: top; */
position: relative;
}
<table class="table">
<tbody>
<tr>
<td>
<div class="arrow-right-1"></div>you can increase or decrease the size of td's height or can put more text
</td>
</tr>
</tbody>
</table>