jQuery 可排序:样式表与列表相同
对比这两个 HTML 片段:
<ul class="ui-state-default" style="list-style-type: none; margin: 0; padding: 0;">
<li>
<table><tr>
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr></table>
</li>
</ul>
将“ui-state-default”应用于列表,如上所示,大致是所需的外观(上面的嵌套表格仅用于使结果看起来与下面的代码类似)。但是,当我仅使用表格尝试相同的操作时:
<table>
<tbody>
<tr class="ui-state-default">
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</tbody>
</table>
我得到几乎相同的外观,但表格的元素之间有难看的白线。而且,TR 没有 LI 那样漂亮的边框。屏幕截图:
我真的想使用该表jQuery UI 可排序版本,但我似乎无法发挥任何 CSS 魔法来使 TR 看起来像 LI 一样漂亮。有什么好主意吗?
编辑: jsFiddle 神奇地使其完美工作 (相关的 css 行直接从我的 jquery-ui 复制/粘贴但是,当我自己创建完全相同的页面(甚至将自己限制为仅粘贴在 jsFiddle 中的 css)并将其加载到网络浏览器中时,它保留了相同的内容。无论我是否添加文档类型来进入/退出怪异模式,都会出现上述错误行为。
<html>
<head>
<style type="text/css">
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #d3d3d3/*{borderColorDefault}*/; background: #e6e6e6/*{bgColorDefault}*/ url(images/ui-bg_glass_75_e6e6e6_1x400.png)/*{bgImgUrlDefault}*/ 50%/*{bgDefaultXPos}*/ 50%/*{bgDefaultYPos}*/ repeat-x/*{bgDefaultRepeat}*/; font-weight: normal/*{fwDefault}*/; color: #555555/*{fcDefault}*/; }
.ui-state-default .ui-icon { background-image: url(images/ui-icons_888888_256x240.png)/*{iconsDefault}*/; }
</style>
</head>
<body>
<ul class="ui-state-default" style="list-style-type: none; margin: 0; padding: 0;">
<li>
<table><tr>
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr></table>
</li>
</ul>
<br /><br />
<table>
<tbody>
<tr class="ui-state-default">
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</tbody>
</table>
</body>
</html>
Contrast these two snippets of HTML:
<ul class="ui-state-default" style="list-style-type: none; margin: 0; padding: 0;">
<li>
<table><tr>
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr></table>
</li>
</ul>
Applying "ui-state-default" to a list, as in above, is roughly the desired appearance (nested table above is only used to make the result look similar to code below). However, when I try the same with just a table:
<table>
<tbody>
<tr class="ui-state-default">
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</tbody>
</table>
I get nearly the same look, but the table has ugly white lines between the elements. Also, the TR doesn't have the nice border that the LI does. Screenshot:
I really want to use the table version of jQuery UI sortable, but I can't seem to whip up any CSS magic that will make the TR look nice like the LI. Any bright ideas?
edit: jsFiddle magically makes it work perfectly (relevant lines of css copy/pasted directly from my the jquery-ui css source that I'm using. However, when I create the exact same page myself (even limiting myself to only the css pasted in the jsFiddle) and load it into a web browser, it retains the same erroneous behavior described above, whether or not I add a doctype to enter/exit quirks mode.
<html>
<head>
<style type="text/css">
.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #d3d3d3/*{borderColorDefault}*/; background: #e6e6e6/*{bgColorDefault}*/ url(images/ui-bg_glass_75_e6e6e6_1x400.png)/*{bgImgUrlDefault}*/ 50%/*{bgDefaultXPos}*/ 50%/*{bgDefaultYPos}*/ repeat-x/*{bgDefaultRepeat}*/; font-weight: normal/*{fwDefault}*/; color: #555555/*{fcDefault}*/; }
.ui-state-default .ui-icon { background-image: url(images/ui-icons_888888_256x240.png)/*{iconsDefault}*/; }
</style>
</head>
<body>
<ul class="ui-state-default" style="list-style-type: none; margin: 0; padding: 0;">
<li>
<table><tr>
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr></table>
</li>
</ul>
<br /><br />
<table>
<tbody>
<tr class="ui-state-default">
<td>Testing.</td>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</tbody>
</table>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那是因为 jsFiddle 在
normalize.css
中加载,其中包含,除其他外:如果您取消选中“标准化 CSS”,它会在 jsFiddle 中再次损坏: http://jsfiddle.net/S3ugZ/1/
如果你只添加回 CSS 片段,它就可以工作: http://jsfiddle.net/S3ugZ/2/
所以,这就是您缺少的 CSS。
That's because jsFiddle loads in
normalize.css
, which contains, amongst other things:If you untick "Normalized CSS", it's broken again in jsFiddle: http://jsfiddle.net/S3ugZ/1/
And if you add back just that snippet of CSS, it works: http://jsfiddle.net/S3ugZ/2/
So, there's the CSS you were missing.
这很可能是由于表格元素的额外格式造成的。如果您有 Chrome 浏览器,请完全检查这两个元素,可能有一些 css 应用于 table、tbody、tr 和 td 元素。您需要通过覆盖一些 css 来删除其中的一些内容。
This is due to extra formatting on table elements most likely. If you have a chrome browser, inspect both elements fully, there is probably some css that is being applied to the table, tbody, tr, and td elements. You will need to strip some of that out by overriding some of the css.