Home > Web Front-end > HTML Tutorial > Markup language - another discussion list_HTML/Xhtml_Web page production

Markup language - another discussion list_HTML/Xhtml_Web page production

PHP中文网
Release: 2016-05-16 16:45:55
Original
1300 people have browsed it

Previously in Chapter 1, we discussed several ways to mark lists, and looked at the benefits of marking them as unordered lists with

    and
  • . This method can mark the structure of the list and ensure that all Browsers and devices can display its content correctly, and it also allows us to add various styles to it using CSS.
    In various circumstances, it would not be difficult to fill up the whole book with all the ways to mark the list when dealing with individual problems. I don’t plan to fill the whole book, but I do plan to use a separate chapter to discuss the exceptions. Several categories of lists other than unordered lists. Explore several situations in which lists are appropriate.
    List is a powerful tool for organizing page structure, adding meaning to each independent item, allowing you to add independent styles with CSS later.
    Let’s start by looking at a numbered list of items, and two ways to mark such a list. Maybe you can see at a glance which method is more beneficial, but I’ll elaborate on the example again so that Emphasizes the importance of structured markup and using the right tools to solve problems. Which method of notation is best for numbered item lists?
    Suppose you plan to mark a list of steps, with each item preceded by a number. We will look at two different ways to achieve this goal, and explain why one method is more suitable. Method A: Order in Chaos
    <ul>
    <li>1. Chop the onions.</li>
    <li>2. Saute the 
    onions for 3 minutes.</li>
    <li>3. Add 3 cloves of 
    garlic.</li>
    <li>4. Cook for another 3 
    minutes.</li>
    <li>5. Eat.</li>
    </ul>
    Copy after login

    The previous list may be one of the worst recipes in the history of cooking. But it is good as a simple example. It might be better to add some salt and eggs, or... whatever, Back to topic.
    Method A We choose to mark these steps as an unordered list in order to get all the benefits we mentioned in Chapter 1, we add structure to the content, and know that most browsers, screen readers and other devices can If we handle this part of the content correctly, we can also easily specify styles for it using css later, which is great! But... numbers game
    Since this is a numbered list, we add a number before each item and a period after the number to identify the order of each step, but if you need to do it later between step 2 and step 3 What if we add a new step? Now we need to (manually) renumber all the items after the new step. For this list, it is not a troublesome thing, but if you are modifying a list with 100 items list, the modification process becomes very tedious. A small dot symbol appears
    Since we marked the structures in this example as an unordered list, you will see a little dot symbol before each numbered item (just like Figure 8-1). You might also like the little dot symbol. Symbol, of course you can remove it through CSS if you don’t like it, but when you browse this list without using CSS, you will definitely see these little dot symbols again.

    Markup language - another discussion list_HTML/Xhtml_Web page production

    Picture 8-1. The browser closes the result of CSS reading method A
    There is a simpler, more meaningful, and easier to maintain method. Let’s take a look at method B. Method B: Ordered list

    <ol>
    <li>Chop 
    the onions.</li>
    <li>Saute the onions for 3 
    minutes.</li>
    <li>Add 3 cloves of 
    garlic.</li>
    <li>Cook for another 3 
    minutes.</li>
    <li>Eat.</li>
    </ol>
    Copy after login

    I'm sure this is what most people do, but that doesn't mean we all don't use method A in some situations, for some reason.

      stands for "Ordered List" ( ordered list), so semantically we are using the correct elements to solve the problem at hand. What else is special about Method B? Autonumbering
      Maybe you find that we don’t have to manually number each list item. When using
        , numbers will be automatically generated in sequence. If our step list contains more than 100 items, and we When we need to insert several new steps in the middle, we only need to simply insert the new
      1. item in the correct position, and the browser will automatically renumber it, just like magic.
        If we use method A, we need to manually correct all the numbers when inserting each item. I can think of more interesting work to do than this...
        Figure 8-2, the 11th version browser displays the effect of method B, with numbers automatically added before each step.
        Markup language - another discussion list_HTML/Xhtml_Web page production

        Figure 8-2 Browser display effect of method B The Happy Wrapper, Part 2
        Another benefit of method B is that when a long list item is wrapped, it will be indented after the generated number, while method A will be folded below the number (Figure 8-3)
        Markup language - another discussion list_HTML/Xhtml_Web page production

        Figure 8-3 Comparing method A and method B line break effect list types
        Although the default numbering style of ordered lists is usually Arabic numerals (1, 2, 3, 4, 5, etc.), we can change the numbering style by using the list-style-type property of CSS. And list- style-type can choose one of the following: decimal: 1,2,3,4,...(usually the default value) upper-alpha: A,B,C,D... lower-alpha: a,b,c,d... upper-roman: I,II,III,IV... lower-roman: i,ii,iii,iv... none: No numbering
        So, for example, if we want method B to produce uppercase Roman numbers, we can achieve the goal with the following CSS:

        ol li {
        list-style-type: 
        upper-roman;
        }
        Copy after login

        图8-4就是方法B配上这份CSS在浏览器内的显示效果,我们的步骤列表现在不再是预设的阿拉伯数字,而是改用罗马数字编号了.当然,标记的部分仍然完全相同.改变主意了吗?只要做点小小的修改,换上先前列出的其他样式,就能马上把清单的编号方式改成你喜欢的样子.
        Markup language - another discussion list_HTML/Xhtml_Web page production

        图8-4 换用罗马数字的有序清单
        HTML的type属性:之前可能有些人会直接在

          标签中使用type属性,把清单的编号方式换成罗马数字,英文字母等等,然而,为了支持稍早所述的CSS规则,从HTML 4.01标准开始就不建议使用type属性了,因此,你不应该再使用type属性,应该改用CSS.
          稍后,在技巧延伸中,我们会以CSS为这个有序清单加上样式.但现在让我们先看看另一个清单种类的例子.


          一群名词与解释的标记法,哪种更好?
          OK,这个问题已经提供够多线索,本身差不多就是答案了.在我们看完下面两种方式之后,你就会知道刚才这句话的意义了.比问题本身更重要的是:方法A是个在标记名词与解释时经常使用的做法,而方法B其实是一种很少人会使用的清单,但是它能应用在许多情况下,结构也更灵活.
          首先,让我们很快的看看你可能十分熟悉的名词 / 解释标记法,特别是W3C定下的几个标准: 方法A

          <ul>
          <li>CSS<br />
          A simple mechanism for 
          adding style (e.g. fonts, colors, spacing) to Web 
          documents.</li>
          <li>XHTML<br />
          A family of current and 
          future document types and modules that reproduce, subset, and extend HTML, 
          reformulated in XML.</li>
          <li>XML<br />
          A simple, very 
          flexible text format derived from SGML.</li>
          </ul>
          Copy after login

          这个方法看起来有点道理,使用无序清单,并且以
          标签隔开名词与定义内容.
          然而,如果我们想为每个名词(CSS,XHTML和XML)与定义内容指定不同的样式,那么要怎么做呢?使用方法A时的唯一选项,是加上某些可以指定样式的标签,像是额外的.从维护的角度来看,这不是个理想的做法.
          图8-5是方法A在一般浏览器中的显示效果,名词与定义分别处于单独一行.
          Markup language - another discussion list_HTML/Xhtml_Web page production

          图8-5 以一般浏览器显示方法A的效果
          除了不能为每行制定特殊的样式外,方法A并没有什么缺点,但是已经足够当成接口,让我凸显方法B使用的清单种类 -- 定义清单. 方法B

          <dl>
          <dt>CSS</dt>
          <dd>A simple 
          mechanism for adding style (e.g. fonts, colors, spacing) to Web 
          documents.</dd>
          <dt>XHTML</dt>
          <dd>A family of 
          current and future document types and modules that reproduce, subset, and extend 
          HTML, reformulated in XML.</dd>
          <dt>XML</dt>
          <dd>A 
          simple, very flexible text format derived from SGML.</dd>
          </dl>
          Copy after login

          定义清单(

          )内容由两种额外标签组成:
          (定义名词)以及
          (定义描述).对我们的例子来说,定义清单完美符合内容代表的意义 -- 因为我们就是在定义一系列名词,解释.
          根据预设值,大多数可视化浏览器会将定义描述
          显示在独立的一行内,并且稍微缩进(图8-6),当然我们可以利用CSS视需要修改缩进设定.
          Markup language - another discussion list_HTML/Xhtml_Web page production

          图8-6 一般浏览器显示方法B的效果 由结构引导样式
          语义上来说,方法B十分完整,让我们能为清单的每一个元素使用独立标签,这让我们能分别为名词,揭示内容制定特定样式.
          举例来说,我们能做个简单修改,以CSS把

          变成粗体.只要几行声明就能达成这个目的.完全不必修改标签内容.

          dt {
          font-weight: 
          bold;
          }
          Copy after login

          只要这样就够了,不必为清单内容加上,甚至是标签,现在所有的

          都会变成粗体,与图8-7一样.
          Markup language - another discussion list_HTML/Xhtml_Web page production

          图8-7 方法B为

          加上font-weight:bold的效果 加上图片
          或许你发现我喜欢用CSS为标签加上小图标,我喜欢这个做法的理由,是因为我能使用CSS的background属性打扮页面,同时把属于装饰性,不重要的图片与页面内容,结构分开.
          更换,增加或移除这些图片的动作十分简单,因为我不需要修改标签内容就能完成这些变动.
          对定义清单来说,如果加上小箭头图标,从名词指向定义内容的话,应该很有意思.我们能以下面这段CSS轻松加上这个效果:

          dt {
          font-weight: 
          bold;
          }
          dd {
          margin-left: 15px;
          padding-left: 
          15px;
          color: #999;
          background: url(dd_arrow.gif) no-repeat 0 2px;
          }
          Copy after login

          我们所做的修改,首先是以margin-left:15px稍微拿掉一些

          标签预设的外补丁,接着,我们把定义描述的颜色换成灰色,使其与
          的区别更大.同时在描述文字的左边,理顶端2像素的地方放上一个小巧的橘色箭头图标,并且在描述文字的左边留下15像素的内部定,让图标不会与文字重叠,图8-8就是完成的效果.
          Markup language - another discussion list_HTML/Xhtml_Web page production

          图8-8 加上图标,凸显文字关联性的定义清单
          如你所见,使用定义清单结构,我们就能轻易地为每个构成项目指定独特的样式,让版面更丰富,而完全不必修改标签内容,我们也能确信不支持样式的浏览器仍会以有组织,容易阅读的方式显示这个清单. 其他应用
          又见很重要的事情必须指出:那就是定义清单的用途不仅限于标注名词,定义内容.定义清单还能用来标注对话,导航条,甚至是表单排版.
          我们甚至可以引用W3C在HTML 4.01规范中对于定义清单的定义:(http://www.w3.org/TR/html4/struct/lists.html)
          "以

          标签建立的定义清单,通常包含一系列名词,定义内容(虽然定义清单也能应用在其他地方)"
          所以,别害怕把定义清单用在名词,解释内容之外的地方!


          概要
          本章到目前为止,我们看了另外的两种清单:有序清单,定义清单.我们发现借着使用这些清单结构,代替无序清单加上额外标签的做法,能够让我们更容易控制样式,同时也让清单变得更容易维护.
          接着以我们本章最初的步骤清单当作例子,用CSS为他调整一下样式. 技巧延伸
          让我们复习一下本章最初的有序步骤清单:

          <ol>
          <li>Chop 
          the onions.</li>
          <li>Saute the onions for 3 
          minutes.</li>
          <li>Add 3 cloves of 
          garlic.</li>
          <li> Cook for another 3 
          minutes.</li>
          <li>Eat.</li>
          </ol>
          Copy after login

          没有加上任何CSS的话,浏览器的显示效果与图8-2差不多,就与本书其他的结构化标记语法示例一样,在导入CSS的时候,有序清单是一组容易指定样式的标签组.
          我们知道,由于使用了正确的结构,因此不支持CSS或把CSS关闭的浏览器也能正确显示出清单的内容.
          让我们装饰的花俏一些,先来自定每个项目之前的编号吧. 识别每个项目
          为了让我们能存取每个清单项目,把它的编号换成更华丽的样式,我们需要为每个

        1. 标签加上id,我们也会为整个有序清单加上id,让我们能为这个清单指定特定样式,而不影响其他所有的
            .

            <ol id="recipe">
            <li id="one">Chop the onions.</li>
            <li id="two">Saute the onions for 3 
            minutes.</li>
            <li id="three">Add 3 
            cloves of garlic.</li>
            <li id="four"> 
            Cook for another 3 minutes.</li>
            <li id="five">Eat.</li>
            </ol>
            Copy after login

            现在我们能识别每个项目了,因此我们对清单内每个元素的样式都进行完整控制.值得一提的是,在此为每个项目加上独特的id之后,我们就无法依赖有序清单的"自动编号"功能了.如果稍侯在中间插入新步骤的话,我们就得自己变更往后步骤的id值,在此事先提醒一下. 自定数字
            为清单建立自定数字的第一个步骤是用list-style-type属性去掉#recipe元素预设的自动产生数字的效果:

            #recipe {
            list-style-type: 
            none;
            }
            Copy after login

            图8-9 是用上面这条规则去掉数字之后的清单显示效果.

            Markup language - another discussion list_HTML/Xhtml_Web page production

            图8-9 用CSS关闭数字编号之后的有序清单
            现在我们已经防止自动产生数字了,接着就能以自己的数字图片代替.用photoshop(或是你喜欢的绘图工具)建立5个GIF图片,一个数字一张图.图8-10是我用红色Prensa字体建立的五个数字.

            Markup language - another discussion list_HTML/Xhtml_Web page production
            图8-10 用在有序清单内的五个GIF图片 把数字加到CSS中
            由于尺寸较大,因此我们需要为每个清单项目加上一点内外补丁,以便为数字图片留下足够的空间让它们显示成背景,我们也会在每个步骤下面加上一条浅灰色的边线.
            我们能以继承选择器 #recipe li将这些规则套用到位于#recipe 中的

          1. 上,这让我们不必为每个id重复定义这些规则.

            #recipe {
            list-style-type: 
            none;
            }
            #recipe li {
            padding: 10px 50px;
            margin-bottom: 
            6px;
            border-bottom: 1px solid 
            #ccc;
            }
            Copy after login

            把这些设定值套用到清单内的每一个

          2. 之后,接着我们就能为每个id指定对应的数字图片.

            #recipe {
            list-style-type: 
            none;
            }
            #recipe li {
            padding: 10px 50px;
            margin-bottom: 
            6px;
            border-bottom: 1px solid #ccc;
            }
            #one 
            {
            background: url(ol_Markup language - another discussion list_HTML/Xhtml_Web page production) no-repeat 6px 
            50%;
            }
            #two 
            {
            background: url(ol_Markup language - another discussion list_HTML/Xhtml_Web page production) no-repeat 2px 
            50%;
            }
            #three 
            {
            background: url(ol_Markup language - another discussion list_HTML/Xhtml_Web page production) no-repeat 3px 
            50%;
            }
            #four 
            {
            background: url(ol_Markup language - another discussion list_HTML/Xhtml_Web page production) no-repeat 0px 
            50%;
            }
            #five 
            {
            background: url(ol_Markup language - another discussion list_HTML/Xhtml_Web page production) no-repeat 6px 
            50%;
            }
            Copy after login

            加上6px 50%会让图片摆放在离左边6像素,上下50%的位置上,让它对齐水平中线. 结果
            图8-11是以一般浏览器查看最终结果的样子,每个图片都显示在项目的左侧,而每个步骤的底部都有一条灰色直线,进一步把它们区分开来.
            1Markup language - another discussion list_HTML/Xhtml_Web page production

            Figure 8-11 The final effect viewed using a general browser
            With a few pictures and a few CSS rules, we added some custom styles to the structured ordered list: once again proving that we can put unimportant pictures outside the tags for easy updates later. . in conclusion
            In addition to no need for list changes, ordered lists and definition lists can also provide corresponding semantic structures and convenient style selection. Use your imagination and try these different list types -- At the same time, use CSS as the basic structure and add a gorgeous coat.
            In the end, you will have a solid foundation that can be displayed correctly everywhere, and at the same time, you can modify the display effect with a powerful browser with CSS.
            Judging from the chapters, half of the book has been translated. Only then do I realize how difficult it is to translate English documents into Chinese... First, you must understand the original author's original intention before you can organize it in your own language... Regarding this one, I still prefer to use a synthetic background image and then use background-position to specify the corresponding background image for each list. At least it will visually reduce the number of times to load the image... Haha

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template