html - 试图让菜单与 html 和 css 内联

标签 html css

我已经使用列表在 html 中创建了一个菜单列表,我已经将该列表添加到一个名为 menu 的 div 中。在我的 css 中,我添加了 display:inline 以尝试使列表以内联方式显示列表,通常这可行,但由于某种原因它似乎不起作用。

这是我的代码

#menu ul {
  width: 100px;
  position: absolute;
  z-index: 1;
  background: white;
  padding-top: 20px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: inline;
}
<div id="menu">

  <ul>

    <li><a href="index.php">Home</a>
    </li>&nbsp; &nbsp; &nbsp;
    <li><a href="about.php">About Us</a>
    </li>&nbsp; &nbsp; &nbsp;
    <li><a href="Specials.php">Specials</a>
    </li>&nbsp; &nbsp; &nbsp;
    <li><a href="terms.php">Terms</a>
    </li>&nbsp; &nbsp; &nbsp;
    <li><a href="contact.php">Contact Us</a>
    </li>&nbsp; &nbsp; &nbsp;

  </ul>

</div>

最佳答案

你需要在你的 ul li 而不是 ul 上放置内联显示,因为你只有一个 :)

因此,将您的 css 更改为:

    #menu ul li
{

 width: 100px;
 position: absolute;
 z-index: 1;
 background: white;
 padding-top: 20px;
 margin: 0;
 padding: 0;
 list-style:none;
 display:inline;
}

关于html - 试图让菜单与 html 和 css 内联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36573902/

相关文章:

c# - 为什么 Razor 在 html 元素上设置的条件样式总是 html 编码不正确

javascript - 使背景变为空白并重定向 IE 8 及更早版本

html - 如何显示 block 内联?

jquery - Access-Control-Allow-Origin header 包含无效值

html - 无法解码下载的字体和 OTS 解析错误 : invalid version tag

javascript - 选择具有相同 ID 的第 n 个 html DOM 元素

html - iOS 6 和 iOS 7 中的 UIWebView 渲染差异

html - 带照片的 Bootstrap 轮播 : optimal image size?

html - CSS 多列问题 : one paragraph with unequal heights

html - if else 的内联样式