Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    59
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Get border and padding width of cell

    Hello all,
    I need to get the border and internal padding width of a cell of a table. I plan to subtract these values from the offsetWidth to get the content width, and use that to set the style.width of another cell. Unfortunately, I can't find a tried-and-true way to get the border and padding width. Anyone got an idea?

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    454
    Thanks
    0
    Thanked 20 Times in 20 Posts
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #3
    New Coder
    Join Date
    Jun 2011
    Posts
    59
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Those are properties for a table. I need properties for a table cell.

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Maybe you can use this ?
    Subtract them to get border plus padding.
    Can't swear that it works everywhere.
    Code:
    <style>
    table { border-width: 7px; 
    border-style: outset; } 
    td { border-width: 5px; 
    border-style: outset; 
    padding:5px}
    p { border-width: thick;
    border-style: solid; }
    </style>
    <script>
    	
    
    function getOuterDimensions(el) {
    	return [el.offsetHeight, el.offsetWidth];
    };
    
    function getInnerDimensions(el) {	
    	return [el.clientHeight, el.clientWidth];
    };
    function init(){
    var elSpan = document.getElementById("elSpan");
    var elTd = document.getElementById("elTd");
    alert(getOuterDimensions(elTd))
    alert(getInnerDimensions(elTd))
    alert(getOuterDimensions(elSpan))
    }
    </script>
    <body onload="init()">
    <table>
        <tr>
    	<td id="elTd">
    	    <span id="elSpan">hello</span>
    	</td>
        </tr>
    </table>
    
    </body>
    Last edited by DaveyErwin; 03-23-2012 at 07:11 PM.

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Quote Originally Posted by StevenTNorris View Post
    Hello all,
    I need to get the border and internal padding width of a cell of a table. I plan to subtract these values from the offsetWidth to get the content width,
    why not just get the content width ?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •