1 行文本的语义 HTML
我有一个包含事件的 div 我希望它看起来像这样
[-----] TITLE
[-IMG-] Author
[-----] Date
我现在设置它的方式是这样的
<div class="book">
<img class="thumb">
<h2>TITLE</h3>
<span>Author</span>
<br />
<span>Date</span>
</div>
我认为我不应该为作者使用 描述,因为我希望它们位于多行上(同时执行
display:block
会使左侧的浮动元素表现得很奇怪),但我不知道
是否有效code> 标签很合适,因为它只有 1文本行。
我应该为此使用什么标签?
谢谢!!
I have a div containing an event I want it to look like this
[-----] TITLE
[-IMG-] Author
[-----] Date
The way I have it set up now is like this
<div class="book">
<img class="thumb">
<h2>TITLE</h3>
<span>Author</span>
<br />
<span>Date</span>
</div>
I don't think that I should be using <span>
for the author and Description since I want them on multiple lines (also doing display:block
makes it act weird with the floated element to the left) but I don't know if a <p>
tag is suitable since it's only 1 line of text.
What tag should I be using for this?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
作者是一个副标题,我会使用
作为日期,理想的情况是使用 HTML 5 时间标记,但这会给旧版浏览器和 IE 带来一些复杂性,因此如果您想要换行符,我建议使用
。
这些元素将为您提供所需的线制动,并且在语义上是正确的。
PD:正如 @Will Martin 提到的,建议您将
alt
属性与图像标签一起使用。Author is a subheader, i would use
<h3>
as for date the ideal would be to use HTML 5 time tag but this brings some complications in older browsers and IE so i would recommend using<p>
if you want the line break.This elements will give you the line brakes you want and are semantically correct.
P.D: As @Will Martin mentioned it is recommended that you use the
alt
attribute with the image tag.虽然不是严格意义上的段落,但我认为
标签在这里最合适。
您正在分离不同但相关的信息类型。仅仅因为它不是句子形式,并不意味着使用
以及其中信息类型的类没有任何意义。
无论您最终决定哪种,请记住设计与元素是分开的。也就是说,它们处于不同的路线这一事实不应成为您的主要决策点。
While not strictly paragraphs, I think that the
<p>
tag is most appropriate here.You are separating out different, but related, types of information. Just because it isn't in sentence form, doesn't mean it doesn't make some sense to use
<p>
, with classes for the type of information in them.Whichever you end up deciding, remember that the design is separate from the elements. That is, the fact that they are on different lines shouldn't be your primary decision point.
从amosriveras 2011年的答案开始,我会做不同的事情:
HTML 4.01:
h2
必须是第一个元素,否则img
不会成为此标题范围的一部分div
而不是h3
(不,不是p
,因为它不是段落)div
而不是p
HTML5:
article
而不是div
time
for “Date”使用
dl
也是可能的:img
可以< /em> 被放置在dd
,例如使用dt
“照片”或类似的内容(取决于上下文)。只有当图像与书籍/活动确实相关时我才会这样做。Starting with amosriveras answer from 2011, I'd do things different:
HTML 4.01:
h2
has to be the first element, otherwise theimg
would not be part of this heading scopediv
instead of ah3
(no, notp
, because it is not a paragraph)div
instead ofp
HTML5:
article
instead ofdiv
h1
time
for "Date"Using a
dl
would be possible, too:img
could be placed in add
, for example with adt
"Photo" or something like that (depends on the context). I'd only do that if the image is really relevant to the book/event.在阅读了 @Mazlix 对 @Amosrivera 的回答的评论后,我想建议一个定义列表。
如果您尝试使用其中包含多个 DT/DD 对的单个 DL,样式可能会变得暴躁,但您可以轻松地使用一大堆定义列表。
编辑:
@David Thomas 比我先一步。啊,好吧,这就是生活。
After reading @Mazlix's comment on @Amosrivera's answer, I'd like to suggest a definition list.
The styling might get tetchy if you try to a single DL with multiple DT/DD pairs within it, but you could just as easily use a whole bunch of definition lists.
EDIT:
@David Thomas beat me to the punch there. Ah well, c'est la vie.