Chrome 版本: 23.0.1271.95 m操作系统: 视窗 7 64 位
请检查测试页面 http://jsfiddle.net/CTdQd/2/或源代码吹气。
在页面中有一个父div,样式为"显示:内联块;位置:相对;",有3个不同宽度和高度的孩子。只有一个孩子有"相对"地位,另外两个有"绝对"地位。在 3 个子级之间切换"相对"位置时,父div 的高度会正确更新,但宽度不会更改,其宽度不会改变。在Firefox和IE中没问题。这是铬错误吗?
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>test</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<style>
#wrap {
border: 1px solid #F00;
display:inline-block;
position:relative;
}
.out {
position:absolute;
left: 0;
top: 600px;
}
.out.in {
position:relative;
left: 0;
top: 0;
}
</style>
</head>
<body>
<div style="width:600px;height:400px;border:1px solid #DFDFDF;text-align:center;overflow:hidden;">
<div id="wrap">
<div id="item1" class="out in" style="width:200px;height:200px;background-color:#0F0;">200*200</div>
<div id="item2" class="out" style="width:300px;height:100px;background-color:#00F;color:#FFF;">300*100</div>
<div id="item3" class="out" style="width:400px;height:300px;background-color:#DDD;">400*300</div>
</div>
</div>
<p id="log"></p>
<div style="margin-top:10px;">
<input type="submit" id="test1" value="show1">
<input type="submit" id="test2" value="show2">
<input type="submit" id="test3" value="show3">
</div>
<script>
$(function() {
$('input').click(function() {
var parent = $('#wrap');
$('.in').removeClass('in');
$('.out').eq($(this).index()).addClass('in');
$('#log').text('the parent div's width: ' + parent.width() + 'px, height: ' + parent.height() + 'px');
});
});
</script>
</body>
</html>
我相信这是WebKit中的一个错误。我为此提交了 WebKit 错误104872。