以下情况:
<body>
<div style="position:fixed; width:100%">[place holder for header]</div>
<div style="position:relative;width:100%;margin-top:100px">[content]</div>
</body>
我需要标题始终可见且位于顶部,因此该标题应该带有位置:固定。
自行调整表头高度后出现问题。如果标题高于 100 像素,则部分内容将被隐藏。
我如何(CSS)动态设置内容 div 相对于标头末尾的开始位置。
我仍在寻找仅 CSS 的解决方案,但目前这里有一个想法,在使用 jQuery 时仅使用一行 JavaScript:
JavaScript
$(document).ready(function () {
$('#content').css('marginTop', $('#header').outerHeight(true) );
});
HTML
<body>
<div id="header" style="[…]">[place holder for header]</div>
<div id="content" style="[…]">[content]</div>
</body>
使用的优点.outerHeight(true)
也就是说,它会处理您可能应用于标题的边框和边距。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)