Chrome浏览器中的HTML fieldset
元素存在问题。
我想要一个固定高度fieldset
,并且在其中有一个可滚动的div
。在我放入legend
之前,一切看起来都很好 - 当我这样做时,div
会从fieldset
的底部溢出。我也检查了Firefox,它没有这样做(即完全符合我的预期)。
其他人看到了吗?这是Chrome的错误吗?有人知道是否有这样的黑客?
<!DOCTYPE HTML>
<html>
<head>
<title>a</title>
<style>
fieldset {
height: 80px;
}
fieldset div {
height: 100%;
overflow-y: scroll;
}
</style>
</head>
<body>
<fieldset>
<legend>Test</legend>
<div>
Foo!<br/>
Foo!<br/>
Foo!<br/>
Foo!<br/>
Foo!<br/>
Foo!<br/>
</div>
</fieldset>
</body>
</html>
答案 0 :(得分:1)
如果您不需要使用legend
元素,另一种解决方案是使用h1
并适当地设置样式。这适用于Chrome和FF。
<!DOCTYPE HTML>
<html>
<head>
<title>a</title>
<style>
fieldset {
height: 80px;
}
h1 {
margin:0;
margin-top:-1em;
font-size:1em;
background:white;
width:33px;
}
fieldset div {
height: 100%;
overflow-y: scroll;
}
</style>
</head>
<body>
<fieldset>
<h1>Test</h1>
<div>
Foo!<br/>
Foo!<br/>
Foo!<br/>
Foo!<br/>
Foo!<br/>
Foo!<br/>
</div>
</fieldset>
</body>
答案 1 :(得分:1)
我能够通过将padding-bottom
添加到仅适用于Chrome的字段集来实现它。这平衡了一些额外的高度%。它很好用,即使在调整大小时也能正常工作(相对一致)。
if (navigator.userAgent.toLowerCase().indexOf('chrome')) { // Replace this with your preferred way of checking userAgent
$('fieldset').css('padding-bottom', '4%'); // Exact percent may vary
}
就像一个注释,我发现这至少是IE8-IE11中的一个问题,所以修复可以应用于IE。
答案 2 :(得分:0)
我看到了溢出。
看起来fieldset div
的高度太高了。尝试
fieldset div {
height: 85%;
overflow-y: scroll;
}
在Chrome中为我工作。
当然,如果没有传说的代码,我不确定是否还有其他问题。