简体   繁体   中英

Positioning Nav Bar with CSS

I'm having trouble positioning my vertical navigation bar to the left of my content Div. Here is what I have and what I want:

在此输入图像描述

The problem, is that it's a fixed position so it's different for monitors that are not a similar size. So I'm guessing I'll need to have relative positioning but I'm not too sure on how to do it.

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;
}

Thanks!

Fixed position will help you keep your menu visible when you scroll down. Otherwise, you should not use it.

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

使用百分比(%)代替像素(px)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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