开发者

Which advantages have definition list (<dd><dt> etc..) and when we should use it?

开发者 https://www.devze.com 2023-01-05 11:14 出处:网络
Which advantages have definition list (<dd><dt> etc..) and when we should use it? (Example: use in Zend_Form, but i dont understand why)

Which advantages have definition list (<dd><dt> etc..) and when we should use it? (Example: use in Zend_Form, but i dont understand why)

Does exist other better options?

(I beginner, but its look to me that is xml use inside html. If I right XML not wide used recently because yaml, file.ini, json each of them in their field more efficient in parsin开发者_运维知识库g then xml format.)

Thanks


this article might be useful to you.

http://www.benmeadowcroft.com/webdev/articles/definition-lists


All HTML tags look like XML. That's because both XML and HTML are closely related to SGML. XML is just a more generalized and "extensible" markup language than HTML.

And I would hardly say that XML is "not widely used", considering that XHTML, RSS, ATOM, RDF, EPUB, XMPP, Microformats, ODF, SOAP, etc. are all XML-based. It's far more popular in general use than YAML, JSON, or ini files—none of which are document markup languages in any case.

So the fact that HTML tags resemble XML is a really silly reason to avoid using a particular tag or set of tags. Markup should be chosen based on the semantic structure of your content, not the popularity of XML in the completely unrelated application of data serialization.

You use DL when you need to represent a definition list. That is, whenever you have something of the semantic structure:

term: definition
term: definition
term: definition
...

Strictly speaking, definition lists ought to be used only to define terms as in a glossary. But in practice, it's used for a lot more than that. Because HTML doesn't provide tags for specifying other types of pair relationships, DL is used as a catch-all in this area.

Aside from defining terms, DL is also used for dialog: the DT element holds the speaker's name, and DD holds the line spoken.

A form can also be represented as a definition list, but using the LABEL tag is more semantically correct IMO.

I usually use DL when I have to list a set of attributes and their values, e.g.:

File Name: Chloroform Girl.avi
File Size: 320 MiB
File Type: Video


In HTML, <dl/> must be used each time you need a list of words with definitions. In practice, definition list is used in the situations where a simple list (unordered <ul/> or ordered <ol/>) is not enough.

For example, you want to display a list of files to download. Each file has an icon, a name, a size and a download button.

  1. First, you can put everything in a <table/>. That's what was done ten years before, when CSS was not used as intensively as today, and when the separation between content and presentation was not too clear.

  2. Then, you can just put everything in <div/>s: each file in a <div/>, each file name in a <div/>, etc. The problem is that the code will be longer, less easy to understand and more difficult to maintain.

  3. Then, you may want to put a <ul/> with plenty of <div/>s inside. This is similar to the (2.)

  4. Finally, you can use a definition list. The advantages will be a reduced size of HTML code and a code easier to maintain. By the way, accessibility will be increased: with CSS disabled, your page will still be readable (whereas with embedded <div/>s, the user will have much pain to understand that it is a list of files).

0

精彩评论

暂无评论...
验证码 换一张
取 消