html - 使用 CSS 定位导航栏

标签 html css

我无法将垂直导航栏定位到内容 Div 的左侧。这是我拥有的和我想要的:

enter image description here

问题在于它是一个固定位置,因此对于不同尺寸的显示器来说它是不同的。所以我猜我需要相对定位,但我不太确定该怎么做。

HTML

<!DOCTYPE html>
<html>
<head>
<title> Home Page </title>
<link rel="stylesheet" type="text/css" href= "styles/styling.css" />
</head>

<div class="container">
  <ul class="nav">.....(Just nav bar stuff)


<div class="content">
<h1>abcd</h1>

<p>abcd</p>
</div>

CSS

.content { 
background-color: #FFFFFF; 
width: 650px; 
padding: 20px;
margin: auto; 
word-wrap: break-word 
}

.container {
position: fixed;
top: 151px;
left: 420px;
}

谢谢!

最佳答案

固定位置将帮助您在向下滚动时保持菜单可见。否则,您不应使用它。

<div class="container">
  <div class="one-third column">
      <ul class="yourmenu">xxx</ul> 
      <div class="filler"></div>
  </div>
  <div class="two-thirds column">
      Your page content here
  </div>
</div>

<style>
    .container {width:960px;margin:auto;}
    .column {float:left;position:relative;}
    .one-third {width:320px;}
    .two-thirds {width:640px;}
    .filler {width:100%;height:10px;}
    .yourmenu {position:fixed;top:100px;} /* do not define left, because it will fix the screen and not the column div */
</style>

关于html - 使用 CSS 定位导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27489927/

相关文章:

html - CSS内联内容后

html - 如何动态设置 ng-model 以对应对象属性

c# - 禁用可编辑的 WebBrowser 控件的保存对话框 C#

html - 具有全屏高度的 3 列布局(固定-流体-固定)

html - 可以使按钮充当超链接或其他类似按钮,但针对另一个框架? (HTML)

javascript - 如何通过选中另一个单选按钮来设置选中的单选按钮

javascript - 禁用元素外部的点击

jquery - 如何使用 html5 Canvas 和 JQuery 工具制作滚动条?

Javascript do while 循环不停止

javascript - 设置要在 div id 中使用的 javascript 变量