1
我需要在div父級容器內部堆疊div。父div容器也是一個孩子或在父容器內。如何獲得子元素與超級父級成比例的百分比
我的問題是,當堆疊的div作爲像素一切都OK;然而,如果我需要滑入一個在下面或之間的div的堆棧有時我失去了一個像素。我知道它不可能有0.3232像素,我假設我失去了小數點的像素。
我有一個常量設置爲var PIXELS_PER_FOOT = 25;
如果我有像下面這樣的結構,我如何設置一個與superparent成比例的子元素的百分比?
<div id="superParent" height='500px' OR 20 Feet >
<div id="anotherParent" height="300px" OR 12 Feet >
<div id="aChild" height=If this div is 3 Feet
I need to get the percentage of 3 foot from 20 foot and
apply
that percentage to its parent or
what I am calling the anotherParent
</div>
</div>
所以如果3/20 = 15%。我需要得到12/20 = 60%,這是我迷路的地方。因爲將15%應用於aChild元素將不正確,因爲其父項不是我從中獲取主要百分比的數字。
我無法使用jQuery。