HTML 中的 Span 标签被视为内联元素。它与 div 标签类似,但 div 标签专门用于块级元素,而 span 用于内联元素。它主要在用户想要将内联元素分组到其代码结构中时使用。 HTML 中的 Span 标签用于通过使用元素 class 或 id 属性为特定内容赋予样式。使用 HTML 文档中的 span 标签本身无法进行视觉更改。它作为 HTML 文档中的内联标记。在代码中使用 span 标签有助于减少代码和 HTML 属性。
定义span标签的语法如下:
语法:
<span class=""> Contents </span>
示例:
<!DOCTYPE html> <html> <head> <title>Span tag in HTML </title> <style> .demo { color: blue; font-size: 200%; position: relative; top: 5px; } </style> </head> <body> <p><span class="demo">О</span>Pride make us artificial and Humility make us real.</p> <p>True fact about life </p> </body> </html>
输出:
以下是使用 应用样式的一些属性。如下:
html中span标签的示例如下:
代码:
<!DOCTYPE html> <html> <head> <title>HTML Span Tag</title> </head> <style> .imgdemo { padding-left:25px; background:url(./Content/data/2.jpg) no-repeat top left; display: inline-block; height: 150px; width: 150px; } </style> <body> <!-- span tags with inline style/css --> <h2>Span tag with text color</h2> <span style="color:brown;"> Do those things which makes your soul happy </span> <br> <h2> Span tag with background color</h2> <span style="background-color:lightblue;"> Everybody have natural beauty. Try look at your picture when you are a baby. Your eyes, eyebrows, lips, body. When you are smiling, crying, staring, etc. That it, you got it.</span> <br> <h2> Span tag with background image</h2> <br> <span class="imgdemo" style="color: azure; font-size: 16px; font-display: block;"> Image as background</span> </body> </html>
输出:
代码:
<!--Example 2--> <!DOCTYPE html> <html> <head> <title>HTML Span Tag</title> </head> <body> <h2> Span tag Examples</h2> <p>Good, Better, Best Never let it rest. <span style="color:crimson;"> "Till your good is better and your better is best" </span></p> <p>Everyday you have a choice -<span style="font-family: cursive; font-weight: 200; font- size: 18px;"> STAY THE SAME OR CHANGE </span> </p> <p>Whenever you see a successful person you only see the public glories, never the private sacrifices to reach them."<span style="background-color: aqua ; color:darkblue;"> "Opportunities don't happen, you create them" </span></p> </body> </html>
输出:
Code:
<!DOCTYPE html> <html> <style> .spandemo { background:url(./Content/data/3.jpg) no-repeat top left; display: inline-block; padding-top: 20px; width: 1800px; height: 500px; } </style> <body> <h2> Span tag for image</h2> <br> <span class="spandemo" style="color: aliceblue; font-weight: bold;"> <p> Nature always wears<br> Color of SPIRIT. </p> <br> Heaven is under our feet <br>as well as over our heads <br> <p> Deep in their roots,<br>all flowers Keep the light </p> <p> My soul steers me<br> into nature's silence</p> </span> </body> </html>
Output:
From all the above information, we came to know that the tag in HTML is used to give styling to inline elements. One can group this styling attribute and specifies them inline. Span tag mainly used to arrange structural sections and proper layout sections on our webpage with the help of inline CSS.
以上是HTML 中的 Span 标签的详细内容。更多信息请关注PHP中文网其他相关文章!