Jump to content

Dynamically calculate a div width


Rain Lover
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...