Semantic HTML tag for displaying a path/directory?

怎甘沉沦 提交于 2020-01-14 13:38:10

问题


Is there any tag that's suited to markup a path or directory?

For example: <path>user/project/</path>

I've checked all new HTML5 tags but there doesn't seem to be one that fits this purpose. So which one would come close?


回答1:


Unfortunately there isn't anything in HTML for that. You could try to wrap it in a <pre> tag or <code> in HTML5. Otherwise you can use a <span> tag and style it how you want it to look like.




回答2:


The code element represents a fragment of computer code. This could be an XML element name, a filename, a computer program, or any other string that a computer would recognize.

https://www.w3.org/TR/html51/textlevel-semantics.html#the-code-element




回答3:


If it's part of code, you could use a code.path.

If it's some sample output you could use samp.path.

If you'd like to list the parts, you could use ol.path and style the way it's displayed:

<ol class="path">
  <li class="dir">user</li>
  <li class="dir">project</li>
<ol>

But if it's just a path, you should wrap it with span.path.




回答4:


What do you think about this:

<input type="text" value="user/project/" readonly="readonly" />

One advantage is that you can easily select the complete path without selecting other text accidentally. On the other hand it's not quite semantic since it's a form element.



来源:https://stackoverflow.com/questions/4868939/semantic-html-tag-for-displaying-a-path-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!