相关疑难解决方法(0)

固定位置但相对于容器

我正在尝试修复它,div所以它总是粘在屏幕的顶部,使用:

position: fixed;
top: 0px;
right: 0px;
Run Code Online (Sandbox Code Playgroud)

但是,div它位于一个居中的容器内.当我使用position:fixed它时,修复了div浏览器窗口的相对位置,例如它在浏览器的右侧.相反,它应该相对于容器固定.

我知道position:absolute可以用来修复相对于它的元素div,但是当你向下滚动页面时,元素会消失,并且不会像上一样粘在顶部position:fixed.

是否有实现此目的的黑客或解决方法?

css position fixed css-position

594
推荐指数
13
解决办法
82万
查看次数

当孩子位置固定时,从 Bootstrap 容器继承宽度

我试图让标题 div 从其父级继承其宽度。标题 div 是position: fixed. 父级包含在引导容器内。

但是,正如您在我创建的代码中看到的那样,它没有正确继承其父级的宽度 - 它从某处添加了一些额外的宽度。

这一切都非常烦人!知道如何解决这个问题吗?

.category-body {
  margin-left: 17% !important;
  width: 67%;
  background-color: red;
  height: 500px;
}
.category-header {
  position: fixed;
  top: 51px;
  width: inherit;
  background-color: green;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="category-body">We are in the category-body
    <div class="category-header">We are in the category-header</div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

http://plnkr.co/edit/yVk15RqDqAac4H2eDJQe

html css css-position twitter-bootstrap

6
推荐指数
1
解决办法
4403
查看次数

标签 统计

css ×2

css-position ×2

fixed ×1

html ×1

position ×1

twitter-bootstrap ×1