我需要在单元格中添加直角三角形。如何在表格单元格中添加三角形
如何做到这一点?
我尝试添加跨度和内跨度图标,但它就会出差错
<span style="position: relative;float:right;top:-30px;">@Html.ImageContent("triangle_bonus.png", "")</span>
我需要在单元格中添加直角三角形。如何在表格单元格中添加三角形
如何做到这一点?
我尝试添加跨度和内跨度图标,但它就会出差错
<span style="position: relative;float:right;top:-30px;">@Html.ImageContent("triangle_bonus.png", "")</span>
你基本上有一个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中不起作用。
有一个very old ticket in 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;
}
我的确发现没有<div>
,但只有当<td>
为空时才有可能实现,这可能无济于事。
在div里面做单元文本是个好主意。但如果你只是把额外的div用于ARROW而不是文本。因为td
已给出宽度和高度,并且文字保持在顶部padding-top:20px;
时会产生问题。
我找到了另一种解决方案,并在所有主要的浏览器进行测试(例如:IF和FF以及)
.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>
你能不能设置样式=“背景:网址(@Html。 ImageContent(“triangle”))... position-attributes ...' – Kane
@Kane,现在试试谢谢 – Mediator
@Kane,谢谢。它的工作。请输入回答 – Mediator