制表符宽度 CSS 属性

发布于 2024-11-24 19:24:52 字数 1330 浏览 2 评论 0原文

WebKit 和 Microsoft 浏览器是否支持像 Firefox 和 Opera 使用 -moz-tab-size-o-tab-size 属性指定制表符宽度的任何方法?

例如,我希望

textarea {
    -moz-tab-size: 4;
    -o-tab-size: 4;
    /* How would I do this in Chrome, Safari, and IE? */
}


[更新:]

我创建了一个 tab-size polyfill ( 演示):

<script> // tab-size polyfill
var codeElements = document.getElementsByTagName('code'), // Applies to all code elements. Adjust to your needs.
codeElementCount = codeElements.length,
e = d.createElement('i');

if(e.style.tabSize !== '' && e.style.mozTabSize !== '' && e.style.oTabSize !== '') {
    for(var i = 0; i < codeElementCount; i++) {
        codeElements[i].innerHTML = codeElements[i].innerHTML.replace(/\t/g,'<span class="tab">&#9;</span>');
    }
}
</script>

<style>
.tab {
    width: 2.5em; /* adjust to your needs */
    display: inline-block;
    overflow: hidden;
}
</style>

注意:这不适用于

Do the WebKit and Microsoft browsers support any method of specifying tab width like Firefox and Opera do using their -moz-tab-size and -o-tab-size properties?

For example, I want the tabs in my <textarea> to have a width of 4 spaces:

textarea {
    -moz-tab-size: 4;
    -o-tab-size: 4;
    /* How would I do this in Chrome, Safari, and IE? */
}

[Update:]

I created a tab-size polyfill (Demo):

<script> // tab-size polyfill
var codeElements = document.getElementsByTagName('code'), // Applies to all code elements. Adjust to your needs.
codeElementCount = codeElements.length,
e = d.createElement('i');

if(e.style.tabSize !== '' && e.style.mozTabSize !== '' && e.style.oTabSize !== '') {
    for(var i = 0; i < codeElementCount; i++) {
        codeElements[i].innerHTML = codeElements[i].innerHTML.replace(/\t/g,'<span class="tab">	</span>');
    }
}
</script>

<style>
.tab {
    width: 2.5em; /* adjust to your needs */
    display: inline-block;
    overflow: hidden;
}
</style>

Note: This wont work on <textarea>s, but only on element's that can contain other elements. If the browser does support tab-size it'll use that instead.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-12-01 19:24:52

tab-size 目前仅由 Firefox 和 Opera 使用您给定的供应商前缀。

对于 WebKit,有一个错误报告要求实现该属性。我相信这方面的工作已经开始,正如该报告的评论中所示。

对于 IE,我在 IE9 或 IE10 中找不到有关 -ms-tab-sizetab-size 实现的任何信息。我想 IE 团队对此一无所知。

tab-size is currently only implemented by Firefox and Opera using your given vendor prefixes.

For WebKit, there's a bug report requesting that the property be implemented. I believe work has already started on it, as can be seen in the comments on that report.

For IE, well, I can't find anything about an -ms-tab-size or tab-size implementation in IE9 or IE10. I suppose the IE team has been none the wiser.

北方的巷 2024-12-01 19:24:52

似乎有一个关于这个主题的类似问题,但它并没有真正完全正确地回答这个问题。但确实如此,显然 CSS 中确实存在制表符,尽管我无法想象浏览器对它的支持有那么好。

在 google 上搜索几乎没有结果有关该主题的信息,进一步让我相信它没有得到很好的实现或使用。希望有帮助。

编辑

W3C 链接确实提到了制表位,但这只是一个工作草案 - 一个提案,并且没有实施。

Seems like there's a similar question on this subject, but it doesn't really quite answer that quite right. It does, however reference that apparently tab stops do exist in CSS, though I can't imagine the browser support is all that great on it.

Searching on google for it brings up little to no information on the subject, further leading me to believe that it isn't very well-implemented, or used. Hope that helps.

EDIT

The W3C link does mention tab-stops, but it was only a working draft - a proposal, and was not implemented.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文