当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Linking definition lists (best practice) or bad idea?

问题描述:

What is the best practice for linking dl list items (Definition lists)

<dl>

<dt>link title 1</dt>

<dd>link description 1</dd>

<dt>link title 2</dt>

<dd>link description 2</dd>

</dl>

linked(?):

<dl>

<a href="#">

<dt>link title 1</dt>

<dd>link description 1</dd>

</a>

<a href="#">

<dt>link title 2</dt>

<dd>link description 2</dd>

</a>

</dl>

or would you use <li> and <br> tags to achieve a similar thing.

<ul>

<li><a href="#">link title 1<br><span class="description">link description 1</span></a></li>

<li><a href="#">link title 2<br><span class="description">link description 2</span></a></li>

</ul>

This is for what is to become part of a mobile app (via phone gap) any help or insight would be brilliant, thanks.

网友答案:

You should not use a tag as direct child of dl. The dd and dt tags are used as direct child. So, you can use:

<dl>
      <dt><a href="#">link title 1</a></dt>
      <dd><a href="#">link description 1</a></dd>

      <dt><a href="#">link title 2</a></dt>
      <dd><a href="#">link description 3</a></dd>
</dl>

This way you maintain the standard of html.

网友答案:

If you are using HTML5 doctype then you can do the following

<dl>
    <a href="#">
      <dt>link title 1</dt>
      <dd>link description 1</dd>
    </a>
    <a href="#">
      <dt>link title 2</dt>
      <dd>link description 3</dd>
    </a>
</dl>

However if you're not then the above won't be valid as dd is a block level element and putting it inside an a which is an inline element will cause your HTML to become invalid

分享给朋友:
您可能感兴趣的文章:
随机阅读: