html - 被嵌套列表移动

标签 html css html-lists

我有一个运行良好的 ul,但是当我在上面的 li 添加一个嵌套的 ul 时,移动。有谁知道为什么?如何解决?

我这里有例子:http://jsfiddle.net/y5DtE/

HTML:

<ul>
  <li> first 
        <ul>
             <li> 1.2 </li>
        </ul>
  </li>
  <li> second </li>
  <li> third eally, really long </li>
</ul>​

CSS:

body {
    margin:0px;
}

ul {
    margin:40px auto;
    list-style-type:none;
    padding:0;
    text-align: center;
}

ul li {
    padding: 0 15px; 
    margin-right: 5px;
    background-color: #f2f2f2;
    display: inline-block;
    height: 30px;
    line-height: 30px;
    font-family: verdana;
    font-size:10px;
    color: #666
}

ul li:last-child { margin-right: 0px; }

ul li ul {
    margin:5px 0;
}​

最佳答案

li {
    position: relative;
}

ul ul {
    position: absolute;
    left: 0;
}

关于html - 被嵌套列表移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13272357/

相关文章:

php - HTML 下拉列表仅将最后一行输入到 mySQL

css - WordPress Genesis 子主题 - 为什么它不拉父 css?

html - IE、溢出和消失的列表项

用于客户数据的 PHP MySQL 嵌套列表

html - 从 <ul> 中删除要点

javascript - 使用 javascript 对 html 列表进行排序

java - 使用 Htmlunit 在 Java 网页上按下切换按钮

html - 垂直文本在内联和外部 css 中的 LI 错误对齐

jquery - 如何使 hc-sticky 插件引用其容器

javascript - 更改图像源和不透明度 jquery 问题