简体   繁体   English

如何使用JS填补可用空间?

[英]How do I use JS to fill up availiable space?

I've been searching the www for a solution dealing with the question: How can I use screen.availWidth or something like it in the second inner div of this fiddle to fill up the availiable space? 我一直在寻找一个解决问题的解决方案:如何在这个小提琴的第二个内部div中使用screen.availWidth或类似的东西来填补可用空间? Is it possible? 可能吗?

Thank you. 谢谢。

Possible indeed: http://jsfiddle.net/6fLDS/57/ 确实可能: http : //jsfiddle.net/6fLDS/57/

The required JS: 所需的JS:

var _otherDivsTotalWidth = 100;
window.onload = function WindowLoad() {
    var oDiv = document.getElementById("test");
    if (oDiv)
        oDiv.style.width = (document.body.scrollWidth - _otherDivsTotalWidth -30) + "px";
}

This requires you to hard code the total width of the other DIV elements, it's possible to read that in code.. shouldn't be complicated to add such thing to the above code. 这要求你硬编码其他DIV元素的总宽度,可以在代码中读取..在上面的代码中添加这样的东西应该不复杂。

This migth be what you want : 这就是你想要的:

<div style="position: relative;">
    <div style="position: absolute; width:50px;border:1px solid red;left: 0;">1</div>
    <div id="test" style="border: green 1px solid; margin: 0 50px;">2</div>
    <div style="position: absolute; width:50px;border:1px solid red;right: 0; top: 0;">3</div>
</div>

Edit : your problem looks like the 3-column layout : http://css-discuss.incutio.com/wiki/Three_Column_Layouts 编辑 :您的问题看起来像3列布局: http//css-discuss.incutio.com/wiki/Three_Column_Layouts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM