简体   繁体   English

CSS显示:内联无效

[英]CSS display:inline have no effect

HTML: HTML:

<!-- MENU -->
        <nav id="menu">
            <li><a href="#">Categories 1</a>
                <ul>
                    <li><a href="#">temp1</a></li>
                    <li><a href="#">temp2</a></li>
                    <li><a href="#">temp3</a></li>
                </ul>
            </li>
            <li><a href="#"<Categories 2</a>
                <ul>
                    <li><a href="#">temp1</a></li>
                    <li><a href="#">temp2</a></li>
                    <li><a href="#">temp3</a></li>
                </ul>
            </li>
        </nav>

CSS: CSS:

#menu {
  background-color: #0000FF;
  height: 20px;
  padding: 15px 0 10px;
  margin-bottom: 20px;
  font: 12px 'DroidSansBold', Tahoma,sans-serif;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 3px 2px 3px #000;
  border-radius: 5px;
  text-align: center;
} 

#menu li{
  display: inline;
}

#menu li a {
  color: #fff;
  text-decoration: none;
  margin: 0 120px;
}

#menu li ul li{
  display: none;
}

#menu li a:hover{
  color: #dc692e;
}

The result looks like this: 结果看起来像这样: 在此处输入图片说明

I can't seem to figure out why my two categories won't accept css display: inline . 我似乎无法弄清楚为什么我的两个类别都不接受CSS display: inline I have an menu under each of the categories that currently is not displayed. 我在当前未显示的每个类别下都有一个菜单。 When I remove the 'under-menu', display:inline works. 当我删除“菜单下”时, display:inline起作用。

Not working JsFiddle: http://jsfiddle.net/LynwV/ 无法使用JsFiddle: http//jsfiddle.net/LynwV/

Thank for all help! 感谢所有帮助!

@claustrofob is right, inline-block is the solution. @claustrofob是正确的,解决方案是inline-block However, @Zenith is also correct. 但是,@ Zenith也正确。 You need to fix your markup. 您需要修复标记。 I would also change how your writing your styles, instead of long element selector chains, put a class on the element you want to target and style it that way. 我还将更改您编写样式的方式,而不是使用较长的元素选择器链,而是将一个类放在要定位的元素上,并以此方式对其进行样式设置。

Your a tag is wrong. 您的标签有误。 <li><a href="#"<Categories 2</a> should be <li><a href="#">Categories 2</a> . <li><a href="#"<Categories 2</a> <li><a href="#">Categories 2</a>应该是<li><a href="#">Categories 2</a> And, as @Zenith said, you can't have a nav followed directly by a LI element. 而且,正如@Zenith所说,您不能在nav后直接加上LI元素。

Try, 尝试,

#menu li{
    display: inline-block;
}

You have invalid markup, as pointed out by @Zenith, and some broken syntax as pointed out by @Josefffs 正如@Zenith指出的那样,您有无效的标记,而@Josefffs指出的是一些语法错误。

Test Link 测试链接

The issue I see is, you have wrapped the list defined by <ul> tags by an another <li> tag which seems to hide the list of items. 我看到的问题是,您已经用另一个<li>标签包裹了<ul>标签定义的列表,该标签似乎隐藏了项目列表。

Try the inspect element for support as well. 也尝试检查元素。

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

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