[英]HTML tag for Short Text
I need to display the following text on an HTML5 page: 我需要在HTML5页面上显示以下文本:
John Smith
Web Designer
Member since 2018
My idea is to have something like: 我的想法是拥有类似的东西:
<div class="user">
<span>John Smith</span>
<span>Web Designer</span>
<span>Member since 2018</span>
</div>
And then use: 然后使用:
div.user span { display: block; }
Or should I wrap each text line in a P tag? 还是应该将每个文本行都包装在P标签中?
Usually I see P tags as for long text ... 通常我看到P标签就像是长文本...
For short text I tend to use: - A (if it is a link); 对于短文本,我倾向于使用:-A(如果是链接); - SPAN (if it is no link); -SPAN(如果没有链接); - H (if it is a title). -H(如果是标题)。
My main doubt is what tab to use when it is a short text (2 to 4 words)? 我的主要疑问是,如果是短文本(2到4个字),应该使用哪个标签?
Perhaps you could use the HTML <br> tag, which seems to be the most simple way of achieving this without CSS. 也许您可以使用HTML <br>标记,这似乎是没有CSS的最简单方法。
<div class="user">
John Smith<br>
Web Designer<br>
Member since 2018
</div>
如果要在单独的行中显示每个项目,请为它们使用div
。
This is a school-book case for XSLT. 这是XSLT的教科书包。
Assuming that you have an XML file like 假设您有一个XML文件,例如
<?xml version='1.0' encoding='utf-8'?>
<div class="user">
<span>John Smith</span>
<span>Web Designer</span>
<span>Member since 2018</span>
</div>
you can transform this with XSLT-1.0 or above to put a <BR />
tag after each entry: 您可以使用XSLT-1.0或更高版本对其进行转换,以在每个条目之后放置一个<BR />
标签:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/div[@class='user']">
<xsl:apply-templates select="span"/>
</xsl:template>
<xsl:template match="span">
<xsl:value-of select="." /><br />
</xsl:template>
</xsl:stylesheet>
Or, to put each entry inside a <p>
tag, replace the second template with 或者,要将每个条目放在<p>
标记内,则将第二个模板替换为
<xsl:template match="span">
<p><xsl:value-of select="." /></p>
</xsl:template>
With XSLT you are flexible to create both outputs with a minimum of changes to the XSLT file and no changes at all to the input XML file. 使用XSLT,您可以灵活地创建两个输出,而对XSLT文件的更改最少,而对输入XML文件的更改则完全没有更改 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.