是否可以在定义列表 (
) 中隐藏(显示:无;)定义术语 (
)?

发布于 2024-10-03 09:47:16 字数 784 浏览 0 评论 0原文

所以我有一个菜单项列表,我试图弄清楚是否应该使用带有类属性的跨度或每个项目的特征的定义列表。以下是我正在考虑的两个选项:

选项 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

始于初秋 2024-10-10 09:47:16

如果您打算选择第二个,则不应使用 display: none;。您最好将文本放置在屏幕之外,以便屏幕阅读器仍然可以看到它。

dt {
    position: absolute;
    left: -9999px;
    top: -9999px;
}

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.

dt {
    position: absolute;
    left: -9999px;
    top: -9999px;
}
摘星┃星的人 2024-10-10 09:47:16

我说使用语义更丰富的代码 (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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文