使用CSS定位导航栏

爆米花727

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

在此处输入图片说明

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

的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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章