简体   繁体   English

创建两列有序列表。我可以在OL和LI标签之间放置DIV吗?

[英]Creating a two column ordered list. Can I put a DIV between the OL and LI tags?

Using the 960.gs framework, I'm trying to create a two columned ordered list where each list item contains a heading and paragraph and the numbering goes across, not down eg the top row contains 1,2 not 1,3. 使用960.gs框架,我正在尝试创建一个两个列的有序列表,其中每个列表项包含一个标题和段落,编号遍历,而不是向下,例如,顶行包含1,2而不是1,3。 The only way I can get it to work is to put a DIV between the OL and LI elements. 我能让它工作的唯一方法是在OL和LI元素之间放置一个DIV。 This doesn't feel right, I'm sure its wrong although I'm not sure why. 这感觉不对,我确定它错了,虽然我不确定为什么。 What is the correct way to achieve this? 实现这一目标的正确方法是什么? I've got the following markup; 我有以下标记;

<div class="container_16">
<ol>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>
    </div>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>
    </div>
    <div class="clear"></div>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>    
    </div>
    <div class="grid_8">
        <li><h2>Heading</h2>
            <p>Paragraph</p>
        </li>    
    </div>
    <div class="clear"></div>
</ol>
</div>

It is invalid to place div elements inside the ol tag. div元素放在ol标记内是无效的。

Only li elements are allowed in there.. ( check the W3C documentation on lists ) 那里只允许使用li元素..( 查看列表中的W3C文档

The theory is to use 该理论是用的

ol{width:200px;}
li{float:left;width:50%;}

demo at http://jsfiddle.net/gaby/ZKdpf/1/ 演示http://jsfiddle.net/gaby/ZKdpf/1/


For the 960.gs system you should use 对于960.gs系统,您应该使用

<ol class="container_16">
    <li class="grid_8">first</li>
    <li class="grid_8">second</li>
    <li class="grid_8">third</li>
    <li class="grid_8">fourth</li>
    <li class="grid_8">fifth</li>
    <li class="grid_8">sixth</li>
</ol>

and add in your css 并添加你的CSS

ol.container_16 li.grid_8{
   display:list-item;
}

to show the numbers again.. 再次显示数字..

demo at http://jsfiddle.net/gaby/ZKdpf/2/ 演示在http://jsfiddle.net/gaby/ZKdpf/2/


Update 更新

Indeed as you mention in your comment you need to clear every two elements, since the height of the li elements is not the same.. 事实上,正如你在评论中提到的,你需要清除每两个元素,因为li元素的高度不一样。

For modern browsers you should add 对于现代浏览器,您应该添加

.benefits li:nth-child(odd) {
    clear: left;
}

or your can turn that in a class and add it to the odd numbered li elements. 或者你可以在一个类中转换它并将它添加到奇数编号的li元素。

You right to 'feel wrong'. 你有'感觉不对'的权利。 Lists contain list-items and nothing else. 列表包含列表项,没有其他内容。 The easiest way, I think to achieve a horizontal numbering, is to float your LIs. 我认为实现水平编号的最简单方法是浮动你的LI。

The above source code is wront. 上面的源代码是wront。 You can't place anything else between 你不能放置任何其他东西

<ol></ol> 

except 除了

 <li></li>

elements. 元素。 You propably have to find another way to style out your lists. 您可能必须找到另一种方式来确定列表的样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM