Semantic HTML: List of Users

自闭症网瘾萝莉.ら 提交于 2019-12-10 17:36:19

问题


How should I mark up a list of users?

Each user has a name, picture, and job title.

How's this?

<h1>Venmo</h1>

<h2>Employees</h2>

<ul>
  <li>
    <article>
      <img src="http://www.gravatar.com/avatar/7e6e0e2b73358e47e0b7f83f8111f75b">
      <h3>Matt Di Pasquale</h3>
      <p>Software Engineer</p>
    </article>
  </li>
  <!-- ... -->
</ul>

Should I remove the article elements? Should I remove the ul & li elements?


回答1:


This isn't so much a list of users as a table of data about the users. Each user has an image, a name and a job title. That gives you rows and columns.

table {
    display: block;
}
tr {
    display: block;
    overflow: auto;
    clear: left;
    margin-bottom: 10px;
}
td {
    display: block;
    width: 200px;
}
td:first-child {
    float: left;
    width: auto;
}
td:nth-child(2) {
    margin-left: 60px;
    padding-bottom: 6px;
    border-top: solid grey 2px;
}
td:nth-child(3) {
    margin-left: 60px;
    padding-top: 6px;
    border-bottom: solid grey 2px;
}
<table>
    <tr>
        <td>
            <img src="http://b.dryicons.com/images/icon_sets/shine_icon_set/png/256x256/black_female_business_user.png" alt="" width="50" />
        </td>
        <td>Jane Smith</td>
        <td>Software Engineer</td>
    </tr>
    <tr>
        <td>
            <img src="http://b.dryicons.com/images/icon_sets/shine_icon_set/png/256x256/black_female_business_user.png" alt="" width="50" />
        </td>
        <td>Jane Smith</td>
        <td>Software Engineer</td>
    </tr>
    <tr>
        <td>
            <img src="http://b.dryicons.com/images/icon_sets/shine_icon_set/png/256x256/black_female_business_user.png" alt="" width="50" />
        </td>
        <td>Jane Smith</td>
        <td>Software Engineer</td>
    </tr>
</table>



回答2:


According to HTML5 W3C Recommendation: 4.4.7 The li element:

Note: While it is conforming to include heading elements (e.g. h1) inside li elements, it likely does not convey the semantics that the author intended. A heading starts a new section, so a heading in a list implicitly splits the list into spanning multiple sections.

So, remove the ul & li elements.



来源:https://stackoverflow.com/questions/32302328/semantic-html-list-of-users

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