Html 跨度元素的替代品是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5137465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are alternatives to the span-element?
提问by phpheini
say you are working without the <p>
element in HTML. How would you stylize a simple text with css? What HTML-Tag would you take? I always used <span>
, but now I saw that span should always be used to group inline-elements (for example <p>
). And thats not the case in my example.
假设您在没有<p>
HTML 元素的情况下工作。你会如何用 css 风格化一个简单的文本?你会带什么 HTML 标签?我总是使用<span>
,但现在我看到应该始终使用 span 来对内联元素进行分组(例如<p>
)。在我的例子中情况并非如此。
Thanks, phpheini
谢谢,菲菲尼
采纳答案by markijbema
First you should look whether some tag matches semantically. For instance, you might have a text which requires emphasis, in which case em
is the best choice. Another case is if you have a heading, which you could style with h1
, ..., h6
. Always first consider this option!
首先,您应该查看某些标签是否在语义上匹配。例如,您可能有需要强调的文本,在这种情况下em
是最佳选择。另一种情况是,如果您有一个标题,您可以使用h1
, ...,来设置样式h6
。总是首先考虑这个选项!
If there really is no meaning to the text you want to style, or at least, not a meaning supported by css, you can use either span
(for inline text) or div
(for block elements).
如果您想要设置样式的文本确实没有意义,或者至少没有 css 支持的意义,您可以使用span
(用于内嵌文本)或div
(用于块元素)。
回答by Paul Millar
You're free to use any tag you wish... (Within reason); Just make sure it's semantic.
你可以随意使用任何你想要的标签......(在合理范围内);只要确保它是语义的。
Just a few you could use:
<div>
<em>
<strong>
<small>
<pre>
只是一些你可以使用:
<div>
<em>
<strong>
<small>
<pre>
回答by Adam P
<div>
<div>
Div tags are basically <span>
tags for block elements instead of inline elements.
Div 标签基本上<span>
是块元素的标签,而不是内联元素。