css - 固定位置在 Chrome 上不起作用

标签 css html css-position

右栏固定位置在 Opera 和 Firefox 上有效,但在 Chrome 上无效,有什么解决方案吗?

#rightcolumn { 
margin: 0px 0px 0px 0px;
float: right;
font-family: Arial;
font-weight: bold;
height: auto;
width: 300px;
display: inline;
position: fixed;
}

最佳答案

1) 首先,删除display: inline因为,如果您希望 block 级元素为 position: fixed , 你不能同时拥有它 inline . fixed position element is outside the normal flow因此,根据定义,也不能是内联的。

2) 其次,删除 float: right因为你想要它fixed . According to the spec ,不可能两者兼而有之。

"...if 'position' has the value 'absolute' or 'fixed', the box is absolutely positioned, the computed value of 'float' is 'none'..." ~ W3C spec

3) 最后,当使用 absolute 时或 fixed ( fixedabsolute according to the spec 的子集),通过添加类似 top: 0; 的内容来设置元素的位置和 right: 0;相对于其父级的边缘放置它。

#rightcolumn { 
    margin: 0;
    font-family: Arial;
    font-weight: bold;
    height: auto;
    width: 300px;
    position: fixed;
    top: 0; <-- adjust accordingly
    right: 0; <-- adjust accordingly
}

这是 Visual Formatting Model spec .

关于css - 固定位置在 Chrome 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8929288/

相关文章:

css - 如何解决使用 css 自定义 radio 输入的问题?

javascript - 如何让固定滚动的 div 与窗口的其余部分一起滚动?

css - 响应式 Div 调整大小

CSS 固定元素移除垂直滚动

css - sass 看多个目录

jquery - 每次点击切换 1 个 div,再次点击关闭之前打开的 div

html - CSS - 背景位置 : top 150px not working

HTML5 和地名引用

滚动时 CSS 位置修复了 chrome 中的奇怪渲染

html - 如何将未知尺寸的图像置于固定尺寸的 float 框中居中?