css - 如何在页面顶部制作如下图所示的固定水平菜单

标签 css

我需要在页面顶部制作一个水平菜单,如下图所示:

enter image description here

我试着弄了一下,但问题是它不显示

.ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  position: fixed;
  /* Set the navbar to fixed position */
  top: 0;
  /* Position the navbar at the top of the page */
  width: 100%;
  /* Full width */
}
li {
  float: left;
}
li a {
  display: block;
  color: white;
  padding: 16px;
  text-decoration: none;
}
<ul>
  <li><a href="#home">الرئيسيه</a>
  </li>
  <li><a href="#news">نبذه عن</a>
  </li>
  <li><a href="#contact">اتصل بنا</a>
  </li>
</ul>

那么如何在页面顶部制作固定水平菜单如上图?

Here是 fiddle 的链接

最佳答案

ul 不是一个类。这是元素。在此处删除点:.ul {...,因此它应该可以工作。

要沿着菜单制作顶部红线,您可以设置 border-top: 4px solid red;

ul {
    border-top: 4px solid red;
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
    position: fixed; /* Set the navbar to fixed position */
    top: 0; /* Position the navbar at the top of the page */
    width: 100%; /* Full width */
}

li {
    float: left;
}

li a {
    display: block;
    color: white;
    padding: 16px;
    text-decoration: none;
}
<ul>
  <li><a href="#home">الرئيسيه</a></li>
  <li><a href="#news">نبذه عن</a></li>
  <li><a href="#contact">اتصل بنا</a></li>
</ul>

关于css - 如何在页面顶部制作如下图所示的固定水平菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42175308/

相关文章:

css - Firefox CSS Animation Smoothing(子像素平滑)

html - css 如何在 Iphone IOS 中将固定的 div 设置为全宽

javascript - 使用 HTML 下拉菜单生成表单

html - Angular 组件和 CSS : child component too big for its parent

css - 在按钮上使用 CSS 定位图像 Sprite

html - 无法在 css <div> 页脚上居中放置文本

php - 如何为 mozilla、chrome 和 IE 编写特定的 CSS

html - 强制页脚在底部

php - 链接样式表中缺少 CSS 元素

jquery - 更改同级元素 z-index 值的增量倒计时