你可以把li元素放在div里面吗? [英] Can you put li elements inside a div

查看:557
本文介绍了你可以把li元素放在div里面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经浏览了w3c和博客,并且没有发现为什么我不能做下面的html:

 < UL> 
< div>< li> 1< / li>< / div>
< div>< li> 2< / li>< / div>
< div>< li> 3< / li>< / div>
< / ul>

直觉上我知道这看起来不正确,但我找不到可以说如果你搜索HTML验证器,你可以快速运行一些代码,看看它是否能够实现这一点。

是否有效。 Div标签作为ul标签的第一级子元素无效。无论你想实现什么,都可以通过使用CSS来设计li标签。


Ok, so I have looked around w3c and blogs and have not found an argument as to why I cannot do the following html:

<ul>
    <div><li>1</li></div>
    <div><li>2</li></div>
    <div><li>3</li></div>
</ul>

I know intuitively this doesn't look right but I can't find a reference that says you can't do it.

解决方案

If you search for "HTML Validator" you can quickly run some code through one to see if it is valid or not. Div tags aren't valid as first level child elements of a ul tag. Whatever you are trying to achieve can be accomplished by styling the li tags with CSS.

这篇关于你可以把li元素放在div里面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆