Css 固定div垂直和右对齐到另一个div

Css 固定div垂直和右对齐到另一个div,css,position,html,Css,Position,Html,导航舱必须垂直固定,并位于集装箱舱的右侧 使用位置:固定和设置值left和top,可以使div保持在同一位置,但左值取决于父div(页面容器)的居中位置 <html> <body> <div id="page-container" style="width: 700px; height:1000px; margin-left: auto; margin-right: auto;background-color:moccasin;"> <div

导航舱必须垂直固定,并位于集装箱舱的右侧

使用
位置:固定
和设置值left和top,可以使div保持在同一位置,但左值取决于父div(页面容器)的居中位置

<html>
<body>
<div id="page-container" style="width: 700px; height:1000px; margin-left: auto; margin-right: auto;background-color:moccasin;"> 

    <div class="content" style=" width: 340px; height:300px; float:left;background-color:mediumseagreen;"> 
        .content
    </div>

    <div class="nav" style="float:left;height: auto; width: 300px; display: block;background-color:lightblue;"> 
        .nav <br><br>This div must:<br> 
     1. be fixed vertically (if scrolling down, you should see me in the same place) <br>
     2. be aligned to the right side of <b>content</b>
    </div>
</div>
</body>
</html>

.内容
.nav

此分区必须:
1.垂直固定(如果向下滚动,您应该在同一位置看到我)
2.与内容的右侧对齐
请参见:

/* new css */
.nav {
    position: fixed;
    margin-left: 340px; /* same as the width on .content */
}