如何使另一个标签的行为完全像pre标签使用CSS? [英] How to make another tag behave exactly like the pre tag using CSS?
问题描述
我想要< code>
标记的行为类似于< pre>
标记。但问题是我在块的开头得到一个换行符。
I want <code>
tags to behave like <pre>
tags. But the problem is that I get a line break at the beginning of the block. How do I get rid of that line break?
这显示了我的意思...
This shows what I mean ...
推荐答案
这似乎是一个浏览器错误。参见例如此网页。 SGML(和HTML)说,浏览器需要删除一个换行符,紧跟在一个开始标记之后,或紧接在结束标记之前。但是看起来大多数浏览器(注意:不是全部)只在< pre>
标记上遵守这个要求,而不是在其他标记,如< code>
标签。
This appears to be a browser bug. See e.g. this page. SGML (and thus HTML) says that the browser needs to remove a newline immediately following an opening tag, or immediately preceding a closing tag. But it appears that most browsers (note: not all) only adhere to this requirement on the <pre>
tag and not on other tags such as the <code>
tag.
所以,它似乎没有太多可以做的。我唯一可能的解决方案,我可以想到的是使用XHTML严格。这是XML,而不是SGML。也许浏览器会等待所有的元素。我不确定,这只是一个想法。
So, it appears there's not much you can do about it. The only possible fix I can think of is using XHTML strict. That's XML, not SGML. Perhaps browsers will treat all elements equally then. I'm not sure, it's just an idea.
这篇关于如何使另一个标签的行为完全像pre标签使用CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!