CSS Reference

"border-spacing" - css property (v. css 2)

  • To specify the distance between the borders of adjacent cells.
  • Must be a 'border-collapse' : separate borders model.
  • Initial value: 2px 2px
  • The property is inherited
  • HTML usage: 'table' and 'inline-table' elements*
  • Browsers that support the border-spacing - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Possible border-spacing values:

Values Comments CSS
length Gives both the horizontal and vertical spacing in a selected unit. 2
length length The first gives the horizontal spacing and the second the vertical spacing, both in a selected unit. 2
inherit Will inherit the value(s) from parent specification. 2

Possible unit identifier:

unit identifier Comments CSS
em The relative unit 'em' is relative to the font size of the element itself. 1
ex The relative unit 'ex' is relative to the font size of the element itself. 1
px Pixels, relative to the viewing device 1
in inches -> 1 inch is equal to 2.54 centimeters. 1
cm centimeters. 1
mm millimeters. 1
pt points -> the points used by CSS2 are equal to 1/72th of an inch. 1
pc picas -> 1 pica is equal to 12 points. 1

Border and border-spacing for a table:

• cell 'height'
cell 'width'
• table 'border' : outset • cell 'border' : inset • table 'border-spacing' : 20px

Property "border-spacing" example:

<!DOCTYPE HTML >
<html  >
  <head>
    <title>Test</title>
    <script type="text/javascript" >
    </script>
    <style   type="text/css">
      table { border: outset 10px green;
              border-spacing: 10px;
              height: 200px; width:300px; }
      td { border: inset 8px; border-color: grey;}
    </style>
  </head>
  <body >
    <table >
      <tr >
        <td ></td>
        <td ></td>
        <td ></td>
      </tr>
      <tr >
        <td > </td>
        <td ></td>
        <td ></td>
      </tr>
    </table>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.borderSpacing="border-spacing value(s)"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:;
var value=cStyle.borderSpacing;
/* If only one value is preset:
   1) Opera returns only one value.
   2) IE, Firefox, Chrome and Safari returns a value pair.
   
IE and Opera will return values in units as set, but
Opera return only integer value(s).
Chrome and Safari returns integer values in pixel(px)
and Firefox returns a float value in pixel(px)*/
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.