悬停时表格行轮廓的想法? CSS 大纲在 Webkit 中的 tr 上失败
我正在尝试构建一个表格(填充实际的表格数据),并在悬停时获得行的轮廓效果。我尝试了一些想法,但跨浏览器问题阻碍了我。很想听听任何想法。
想法#1:将鼠标悬停在 上时添加 CSS outline
。适用于 IE8 和 IE8 FF3,但不是 IE7 或 Chrome(Webkit,所以 Safari 也可能)。为简洁起见,省略了悬停的实际实现:
<table style="margin:10px;width:800px">
<tbody>
<tr style="outline:red solid 3px">
<td>Test 1</td>
<td>Test 2</td>
</tr>
</tbody>
</table>
想法 #2:将
z-index
堆叠z-index
并在几种不同的浏览器中使用代码后,我感到非常沮丧。我在这里尝试的堆叠/排序可能太复杂,无法在不同的浏览器中工作。使用 jquery-ui 和 Position 的示例代码 (http://wiki.jqueryui.com/Position):
[已删除非工作代码链接]
EDIT: Super awesome slightly kludgish solution below including opacity and rounded corners in all but IE. I'll have to do a blog writeup one of these days on all the little issues.
I'm trying to build a table (filled with actual tabular data), and get an outline effect for a row on hover. I've tried a couple ideas, but cross-browser issues are holding me back. Would love to hear any ideas.
Idea #1: Add CSS outline
when hovering over <tr>. Works in IE8 & FF3, but not IE7 or Chrome (Webkit, so probably Safari too). The actual implementation of the hover is omitted for brevity:
<table style="margin:10px;width:800px">
<tbody>
<tr style="outline:red solid 3px">
<td>Test 1</td>
<td>Test 2</td>
</tr>
</tbody>
</table>
Idea #2: Position a <div> under the <tr> that is wider/taller than the <tr>, and use z-index
to stack the <div> below the <tr>, but on top of adjacent <tr>s. This is much more interesting, because I can potentially do rounded corners, opacity, etc. This looked promising, but so do many ideas when implemented first in Firefox. After reading up on z-index
and playing around with code in several different browsers, I'm totally frustrated. The stacking/ordering I'm trying here is maybe too complex to work in different browsers.
Example code using jquery-ui and Position (http://wiki.jqueryui.com/Position):
[non-working code link removed]
EDIT: Super awesome slightly kludgish solution below including opacity and rounded corners in all but IE. I'll have to do a blog writeup one of these days on all the little issues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
2 听起来非常复杂。这个怎么样:
编辑
试试这个:
哎哟..这在 webkit 中仍然失败。
编辑
好的,再试一次...
Webkit 尊重 TR OUTLINE 如果 你给 TR “display:block”,所以,以下工作:
2 sounds terribly complicated. How about this:
EDIT
Try this:
Whoops.. this still fails in webkit.
EDIT
OK, try again...
Webkit honours the TR OUTLINE if you give the TR "display:block", so, the following works:
这是我在问自己的问题后提出的解决方案 - 悬停时显示表格行大纲
您要做的就是使用
bottom-border: 0
删除所有 td 的底部边框。其他单元格的顶部边框将使所有内容保持应有的样子,除了最后一行。最后一行我们用tr:last-child td { Bottom-border: your border style }
修复。最后在您的悬停伪类中设置底部边框。http://jsfiddle.net/S9pkM/16/
This is the solution I came up with after asking my own question on SO - Outline table row on hover
What you do is remove the bottom border for all of the td's with
bottom-border: 0
. The top borders of the other cells will keep everything looking the way they should, except for the last row. The last row we fix withtr:last-child td { bottom-border: your border style }
. Finally in your hover pseudoclass you set the bottom border.http://jsfiddle.net/S9pkM/16/
我让想法 #2 发挥作用,我认为这非常漂亮。必须使用一些技巧。首先,必须将块元素放入
td
元素内,以便使z-index
在多个浏览器中工作。我使用span
元素和display:block
来填充整个td
,这意味着一些td
css 属性将具有放置在这些span
元素内,并进一步嵌套但尚未添加的span
元素(特别是边框和填充)。我添加了一些不透明度和圆角(IE 中没有圆角)。
I made idea #2 work, which I think is pretty nifty. Several tricks had to be used. First, block elements had to be put inside
td
elements in order to getz-index
working in several browsers. I usedspan
elements withdisplay:block
to fill the entiretd
, which means sometd
css properties will have to be put inside thosespan
elements and further nested but not yet addedspan
elements (borders and padding in particular).I added some opacity and rounded corners (no rounded corners in IE).