是否可以在HTML中插入一个制表符,而不必键入 四次吗?
当前回答
我们可以像这样使用style="white-space:pre":
<p>Text<tab style="white-space:pre"> </tab>: value</p>
<p>Text2<tab style="white-space:pre"> </tab>: value2</p>
<p>Text32<tab style="white-space:pre"> </tab>: value32</p>
里面的空白处填满了制表符,制表符的数量取决于文本。
它看起来是这样的:
Text : value
Text2 : value2
Text32 : value32
其他回答
如果空格变得如此重要,那么使用预格式化文本和<pre>标记可能会更好。
CSS
<html>
<head>
<style>
tab:before
{
content: "\00a0\00a0\00a0\00a0";
}
</style>
</head>
HTML
<body>
<tab> #include < stdio.h > <br>
<tab> <br>
<tab> int main (void) <br>
<tab> { <br>
<tab> <tab> printf ("Hello, World!"); <br>
<tab> <tab> return 0; <br>
<tab> } <br>
</body>
</html>
呈现
在段落中插入多个空格(或在段落中间)确实没有什么简单的方法。那些建议你使用CSS的人没有抓住重点。您可能不总是试图从一个侧面缩进一个段落,但实际上,尝试在它的特定位置放置额外的空格。
In essence, in this case, the spaces become the content and not the style. I don't know why so many people don't see that. I guess the rigidity with which they try to enforce the separation of style and content rule (HTML was designed to do both from the beginning - there is nothing wrong with occasionally defining style of an unique element using appropriate tags without having to spend a lot more time on creating CSS style sheets and there is absolutely nothing unreadable about it when it's used in moderation. There is also something to be said for being able to do something quickly.) translates to how they can only consider whitespace characters as being used only for style and indentation.
当没有优雅的方式插入空格,而不必依赖 和,标签,我认为,如果有一个适当命名的标签,允许您快速插入大量的空格(或者如果,您知道,空格一开始就没有被不必要地消耗),那么结果代码将变得更加不可读。
尽管如此,正如上面所说,您最好的选择是使用 插入:插入正确的位置
我已经使用了一个span与行内样式。我不得不这样做,因为我正在处理一个纯文本字符串,需要用4个空格(appx)替换\t。我不能使用 在进一步的过程中,它们被解释,所以最后的标记有非内容空间。
HTML:
<span style="padding: 0 40px"> </span>
我在一个php函数中使用了它:
$message = preg_replace('/\t/', '<span style="padding: 0 40px"> </span>', $message);
阿菲克,唯一的办法就是使用
如果你可以使用CSS,那么你可以使用填充或边距。参看Box模型,而对于ie浏览器,也可参阅ie浏览器的Box模型bug。
推荐文章
- 使伸缩项目正确浮动
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何触发自动填充在谷歌Chrome?
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击