在this fiddle PoC ,如果我想摆脱溢出的垂直滚动条,我需要将我的 JQuery-ui Accordion 的高度降低两个 额外的无法解释的 像素。
- 我处于
'fill'
heightStyle
模式,如下所示。 - Accordion 的高度是主体的高度减去页脚和页眉的高度。 负 2 像素。
- 所有库都是最新版本(在撰写本文时),除了 jquery 不在“3”中。
- 我知道
accordion.refresh()
和 cssflex
但我对“为什么”很好奇,我宁愿在之前使用 calc()我用 flexbox 填充我的 CSS。
$( function() {
$( "#accordion" ).accordion({heightStyle: 'fill' });
} );
html, body {
height: 100%;
}
:root{
--header-height: 40px;
--footer-height: 40px;
--two-unexplained-px: 2px;
}
body {
overflow:auto;
background-color: red;
}
* {
margin: 0px;
padding: 0px;
}
#header, #footer {
background-color: #adf;
}
#header {
height: var(--header-height);
}
#footer {
height: var(--footer-height);
}
#accordion {
height: calc(100% - var(--header-height) - var(--footer-height) - var(--two-unexplained-px));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/>
<div id="header">Header here</div>
<div id="accordion"><h2><a>Work here</a></h2><div>Text Here</div></div>
<div id="footer">Footer here</div>
最佳答案
另外两个像素来自这个规则:
.ui-accordion .ui-accordion-header {
margin: 2px 0 0 0;
}
关于填充模式下的 JQuery-ui Accordion 和溢出 - 无关的 2px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41378104/