Css IE9位置:已修复垂直滚动条问题
我在IE9中遇到了一个问题(IE7和IE8中也是如此;IE6和IE6中不是这样,因为它们不支持Css IE9位置:已修复垂直滚动条问题,css,internet-explorer,internet-explorer-9,overflow,css-position,Css,Internet Explorer,Internet Explorer 9,Overflow,Css Position,我在IE9中遇到了一个问题(IE7和IE8中也是如此;IE6和IE6中不是这样,因为它们不支持position:fixed),如果我将overflow-y:scroll添加到position:fixed元素中的元素,overflow-y:scroll元素上的滚动条占据了元素的部分宽度,而不是在元素的宽度上添加必要数量的像素来为滚动条腾出空间 以下HTML/CSS演示了该问题: <!DOCTYPE html> <html lang="en"> <head>
position:fixed
),如果我将overflow-y:scroll
添加到position:fixed
元素中的元素,overflow-y:scroll
元素上的滚动条占据了元素的部分宽度,而不是在元素的宽度上添加必要数量的像素来为滚动条腾出空间
以下HTML/CSS演示了该问题:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IE9 position: fixed issue</title>
<style>
body, div, html, p {
margin: 0;
padding: 0;
}
.fixed {
left: 10px;
position: fixed;
top: 50px;
}
.outer {
height: 300px;
overflow-y: scroll;
}
.inner {
background: yellow;
height: 500px;
width: 300px;
}
</style>
</head>
<body>
<div class="stats">
</div>
<div class="fixed">
<div class="outer">
<div class="inner">
</div>
</div>
</div>
<script>
var stats = document.querySelector('.stats'),
outer = document.querySelector('.outer'),
inner = document.querySelector('.inner');
stats.innerHTML =
'<p>Outer width: ' + outer.getBoundingClientRect().width + 'px</p>';
stats.innerHTML +=
'<p>Inner width: ' + inner.getBoundingClientRect().width + 'px</p>';
</script>
</body>
</html>
IE9位置:固定问题
正文,div,html,p{
保证金:0;
填充:0;
}
.固定{
左:10px;
位置:固定;
顶部:50px;
}
.外部{
高度:300px;
溢出y:滚动;
}
.内部{
背景:黄色;
高度:500px;
宽度:300px;
}
var stats=document.querySelector('.stats'),
outer=document.querySelector('.outer'),
内部=document.querySelector('.inner');
stats.innerHTML=
“外部宽度:”+Outer.getBoundingClientRect().width+'px”;
stats.innerHTML+=
“内部宽度:”+Inner.getBoundingClientRect().width+'px”;
如果您在Chrome、FF等中运行此代码,您将获得317px的外部宽度和300px的内部宽度。此外,将没有水平滚动条
但是,如果在IE9中运行相同的代码,两种宽度都将报告为300px,这不是我想要的
有没有办法在IE9中解决这个问题?多谢各位