搜索
首页web前端H5教程HTML 中的 span 标签标准用途是什么?

span里面放文字还是放图片还是放其它东西才符合标准呢?

回复内容:

无语义行内元素。
在段内定义与该段样式不同的内容的样式。
同时满足以下条件的内容你可以使用span标签:
1、行内元素(inline)
2、无语义
3、你需要给他添加特定样式或做js钩子的时候

如:
这是一段话,段落里有一些特殊的需要标记的内容,如红色
这是一个箭头:.。可以通过定义该class使其显示为一个箭头。
你还可以输入140 个字。J_zishu用作js钩子 标签被用来组合文档中的行内元素。
使用 来组合行内元素,以便通过样式来格式化它们。

标准属性有:id, class, title, style, dir, lang, xml:lang
事件属性有:onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup 是无语义的内联元素 尝试着理解+汉化下:
DIV和SPAN元素,结合id,class属性,能为文档内容添加容器。DIV为内容提供了块级容器,SPAN提供了行内容器。但是:DIV和SPAN都没有为内容赋予语义。因此,可以使用这类元素结合样式表,语言属性等……来根据个人喜好来DIY下HTML语言。

W3.org 的这段比较抽象。后面它又整了这么一段话:大致意思是,可以使用DIV或者SPAN元素结合id或者class来实现特定的语义或者结构化效果,以补充HTML标记中不包含的标记对象:“客户”,“电话号码”,“emai[注①]”等等;

注:① email 的话,在HTML5中是可以用
标记来语义化的
Suppose, for example, that we wanted to generate an HTML document based on a database of client information. Since HTML does not include elements that identify objects such as "client", "telephone number", "email address", etc., we use DIV and SPAN to achieve the desired structural and presentational effects. We might use the TABLE element as follows to structure the information:




Client information:






Last name: Boyera
First name: Stephane
Tel: (212) 555-1212
Email: sb@foo.org



Client information:






Last name: Lafon
First name: Yves
Tel: (617) 555-1212
Email: yves@coucou.com

然后,在HTML5对于SPAN的文档定义中,
dev.w3.org/html5/spec/s

对于SPAN的定义显得简洁多了:
The span element doesn't mean anything on its own, but can be useful when used together with the global attributes, e.g. class, lang, or dir. It represents its children.
In this example, a code fragment is marked up using span elements and class attributes so that its keywords and identifiers can be color-coded from CSS:
<span class="keyword">for</span> (<span class="ident">j</span> = 0; <span class="ident">j</span> < 256; <span class="ident">j</span>++) {<br>  <span class="ident">i_t3</span> = (<span class="ident">i_t3</span> & 0x1ffff) | (<span class="ident">j</span> << 17);<br>  <span class="ident">i_t6</span> = (((((((<span class="ident">i_t3</span> >> 3) ^ <span class="ident">i_t3</span>) >> 1) ^ <span class="ident">i_t3</span>) >> 8) ^ <span class="ident">i_t3</span>) >> 5) & 0xff;<br>  <span class="keyword">if</span> (<span class="ident">i_t6</span> == <span class="ident">i_t1</span>)<br>    <span class="keyword">break</span>;<br>}
大意就是,SPAN元素它自己本身啥也不是,但是,它在结合诸如:class,lang,或者dir属性时,非常有用。它起到描述了(文档内容)的作用。(样式:class+css;内容语言:lang;dir:文字方向)

另外:回答下这个问题的标题下面的问题=.=

HTML 4.01关于包含元素的定义:
意思就是一个行内级的容器……
HTML 5 的关于包含元素的定义:
Contexts in which this element can be used:
Where phrasing content is expected.
这里提到了个phrasing content 这个东西;而这个东西它介绍到:
Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs.
HTML 中的 span 标签标准用途是什么?
各种标记看图。。或点这个链接dev.w3.org/html5/spec/s

之后它总结了一条通用规则,意思是任何允许包含phrasing content的容器至少要有一个Text类型的儿子结点,并且不能是inter-element whitespace[注②];或者,它的儿子结点可以是embedded content[注③]…… (后面说的是del元素,与span无关,大概意思是del元素里的子元素不会被del的祖先认为是它的后代?意思是del的长辈不认del的后代吗= =)
As a general rule, elements whose content model allows any phrasing content should have either at least one descendant Text node that is not inter-element whitespace, or at least one descendant element node that is embedded content. For the purposes of this requirement, nodes that are descendants of del elements must not be counted as contributing to the ancestors of the del element.
Most elements that are categorized as phrasing content can only contain elements that are themselves categorized as phrasing content, not any flow content.
注②:inter-element whitespace :1. 内容为空的text结点 2.由space characters构成的text结点 , 这两类text结点会被认为是inter-element whitespace (space characters大致就是实现 space 键,tab键等功能的特殊字符)
The space characters are always allowed between elements. User agents represent these characters between elements in the source markup as text nodes in the DOM. Empty text nodes and text nodes consisting of just sequences of those characters are considered inter-element whitespace.
The space characters, for the purposes of this specification, are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), and U+000D CARRIAGE RETURN (CR).

注③:embedded content :顾名思义,嵌入式内容。
Embedded content is content that imports another resource into the document, or content from another vocabulary that is inserted into the document.
  • audio ,
  • canvas ,
  • embed ,
  • iframe ,
  • img ,
  • math ,
  • object ,
  • svg ,
  • video

PS:一翻译起文档就停不下来了- -

另外就是还有一些利用inline的特性来实现交互或者布局的tip吧:
比如:
1 避免点击块状显示标签时,产生误操作

之类的标签,客户端浏览器会自动给block属性,本来点击h1包住的标题才会触发动作,在点击标题外但仍处在h1横条范围内的地方,也会触发。像这种情况,给

等再加一个就可以解决。
2 让元素保持在一行
在某些元素后面再加上其他的不同格式的内容,但不想它到下一行,只能用嵌套。 cnblogs.com/myparamita/
米粽
inline内容的容器,包裹任何inline内容都是符合标准的。


引用自 w3.org/TR/html4...
The DIV and SPAN elements, in conjunction with the id and class attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (SPAN) or block-level (DIV) but impose no other presentational idioms on the content. Thus, authors may use these elements in conjunction with style sheets, the lang attribute, etc., to tailor HTML to their own needs and tastes.
一些元素的修饰常常就是用span
因为是内联不是块级,所以不会对破坏文档流 span 做为内联元素来使用,另外也可以做为JS交互。内联元素有:span,em,strong,small,del等等。 内联元素 没什么意义 一般我都是用来跟JS交互用的 他本身没有什么功能,但用span标签选中后可以用ccs对选中的内容进行统一的格式上的修改。 对特定内容进行格式编辑。

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
掌握microdata:HTML5的分步指南掌握microdata:HTML5的分步指南May 14, 2025 am 12:07 AM

Microdatainhtml5enhancesseoanduserexperienceByByBybyBystructuredDatatoSearchEngines.1)useIteMscope,itemType,anditempropattributestomarkupcontentlikeSoreRoductSssSssSoRorevents.2)

HTML5表格中有什么新功能?探索新输入类型HTML5表格中有什么新功能?探索新输入类型May 13, 2025 pm 03:45 PM

html5introducesnewinputtypesthatenhanceserexperience,简化开发和iMproveAccessibility.1)自动validatesemailformat.2)优化优化,优化OmportizeSmizesemizesemizesemizesemizesemizeSmobobileWithAnumericKeyPad.3)和SimimplifyDtimePutputientiputiNputiNputits。

理解H5:含义和意义理解H5:含义和意义May 11, 2025 am 12:19 AM

H5是HTML5,是HTML的第五个版本。HTML5提升了网页的表现力和交互性,引入了语义化标签、多媒体支持、离线存储和Canvas绘图等新特性,推动了Web技术的发展。

H5:可访问性和网络标准合规性H5:可访问性和网络标准合规性May 10, 2025 am 12:21 AM

无障碍访问和网络标准遵循对网站至关重要。1)无障碍访问确保所有用户都能平等访问网站,2)网络标准遵循提高网站的可访问性和一致性,3)实现无障碍访问需使用语义化HTML、键盘导航、颜色对比度和替代文本,4)遵循这些原则不仅是道德和法律要求,还能扩大用户群体。

HTML中的H5标签是什么?HTML中的H5标签是什么?May 09, 2025 am 12:11 AM

HTML中的H5标签是第五级标题,用于标记较小的标题或子标题。1)H5标签帮助细化内容层次,提升可读性和SEO。2)结合CSS可定制样式,增强视觉效果。3)合理使用H5标签,避免滥用,确保内容结构逻辑性。

H5代码:Web结构的初学者指南H5代码:Web结构的初学者指南May 08, 2025 am 12:15 AM

HTML5构建网站的方法包括:1.使用语义化标签定义网页结构,如、、等;2.嵌入多媒体内容,使用和标签;3.应用表单验证和本地存储等高级功能。通过这些步骤,你可以创建一个结构清晰、功能丰富的现代网页。

H5代码结构:组织内容以实现可读性H5代码结构:组织内容以实现可读性May 07, 2025 am 12:06 AM

通过合理的H5代码结构可以让页面在众多内容中脱颖而出。1)使用语义化标签如、、等组织内容,使结构清晰。2)通过CSS布局如Flexbox或Grid控制页面在不同设备上的呈现效果。3)实现响应式设计,确保页面在不同屏幕尺寸上自适应。

H5与较旧的HTML版本:比较H5与较旧的HTML版本:比较May 06, 2025 am 12:09 AM

HTML5(H5)与旧版本HTML的主要区别包括:1)H5引入了语义化标签,2)支持多媒体内容,3)提供离线存储功能。H5通过新标签和API增强了网页的功能和表现力,如和标签,提高了用户体验和SEO效果,但需注意兼容性问题。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。