首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >固定div垂直和右对齐到另一个div

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

Stack Overflow用户
提问于 2011-06-30 06:26:04
回答 1查看 1.3K关注 0票数 0

导航div必须垂直固定,并位于容器div的右侧。

使用position:fixed;并设置左侧和顶部的值,您可以使div停留在相同的位置,但左侧的值取决于父级div (页面容器)居中。

代码语言:javascript
复制
<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>

​

​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-30 06:34:46

请参阅: http://jsbin.com/afenip/2

代码语言:javascript
复制
/* new css */
.nav {
    position: fixed;
    margin-left: 340px; /* same as the width on .content */
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6527987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档