是否可以在定义列表 () 中隐藏(显示:无;)定义术语 (- )?
所以我有一个菜单项列表,我试图弄清楚是否应该使用带有类属性的跨度或每个项目的特征的定义列表。以下是我正在考虑的两个选项:
选项 1)
// HAML Markup
%article.menu-item
%span.name
Cereal
%span.price
4.00
%span.description
We carry Cap'n Crunch, Frooty Loops and Count Chocula. Milk included.
// Styling
article.menu-item {
.price:before { content: "$"; }
}
选项 2)
// HAML Markup
%article.menu-item
%dl
%dt
Item
%dd
Cereal
%dt
Price
%dd
4.00
%dt
Description
%dd
We carry Cap'n Crunch, Frooty Loops and Count Chocula. Milk included.
// Styling
article.menu-item {
.price:before { content: "$"; }
dt { display: none; }
}
我目前正在使用选项 1,但出于某种原因,选项 2 在我看来在语义上更丰富,因为它定义了产品。我应该选择哪个选项,为什么?
So I have a list of menu items and I'm trying to figure out if I should use spans with class attributes or definition lists for the characteristics of each item. Here are the two options I am considering:
Option 1)
// HAML Markup
%article.menu-item
%span.name
Cereal
%span.price
4.00
%span.description
We carry Cap'n Crunch, Frooty Loops and Count Chocula. Milk included.
// Styling
article.menu-item {
.price:before { content: "$"; }
}
Option 2)
// HAML Markup
%article.menu-item
%dl
%dt
Item
%dd
Cereal
%dt
Price
%dd
4.00
%dt
Description
%dd
We carry Cap'n Crunch, Frooty Loops and Count Chocula. Milk included.
// Styling
article.menu-item {
.price:before { content: "$"; }
dt { display: none; }
}
I'm currently using option 1, but for some reason option two appears to me to be semantically richer since it defines the product. Which option should I go with and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您打算选择第二个,则不应使用
display: none;
。您最好将文本放置在屏幕之外,以便屏幕阅读器仍然可以看到它。If you're going to go with the second you shouldn't use
display: none;
. You'd be better off positioning the text off screen so screen readers can still get at it.我说使用语义更丰富的代码 (2) 并隐藏 dt。也许更具体地说明您要隐藏哪些 dt:
article.menu-item.dt {display: none }
。它将使文本更具可读性,并避免代码中出现 span 和 div 汤。I say go with the semantically richer code (2) and hide the dt. maybe be more specific about which dts you're hiding:
article.menu-item.dt {display: none }
. it will make the text more readable, and avoid span and div soup in your code.