Jump to content

Dynamically calculate a div width


Rain Lover

Recommended Posts

Hi,Here are sample divisions:

<style type="text/css">#grandparent {width:100px;}#parent {overflow:auto; height:100px; }.child {overflow:hidden; margin-left:10px;}</style><div id="grandparent"><div id="parent"><div class="child">1000000000000000000000000</div><div class="child">1000000000000000000000000</div><div class="child">1000000000000000000000000</div><div class="child">1000000000000000000000000</div><div class="child">1000000000000000000000000</div><div class="child">1000000000000000000000000</div><div class="child">1000000000000000000000000</div></div></div>

The <div class="child"> width value is always 10 pixels less than <div id="parent"> width value. How can it be calculated so any width value is given to <div id="parent">, its child gets 10 pixels less than that?Any help is very much appreciated!Mike

Link to comment
Share on other sites

Every document element has an offsetWidth property. It gives you the total width of an element, including padding, margins, and borders. If you access this property of a parent, you can adjust the width of the child.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...