Search code examples
cssmargin

CSS margin inside table


I'm trying with no luck apply right margins inside tables

<html>
  <style>
    input,select {
      width: 100%;
      margin-right: 15px;
      background: red;
    }
  </style>
  <body>
    <table border="2" color="red" width="100%">
       <tr>
         <td width="25%"><input type="text" /></td>
         <td width="25%"><select><option>foobar</option></select></td>
         <td width="25%"><input type="text" /></td>
         <td width="25%"><input type="text" /></td>
       </tr>
       <tr>
         <td width="25%"><input type="text" /></td>
         <td width="25%"><input type="text" /></td>
         <td width="25%"><select><option>foobar</option></select></td>
         <td width="25%"><input type="text" /></td>
       </tr>
    <table>
  </body>
</html>

Example: http://jsfiddle.net/3reat/

Only using CSS it's possible to define this margins 100% - 15px?

http://jsfiddle.net/3reat/2/


Solution

  • try css3 calc

    (e.g)

    margin: calc(100% - 15px);
    margin: -webkit-calc(100% - 15px);
    margin: -moz-calc(100% - 15px);
    

    Reference : https://developer.mozilla.org/en-US/docs/CSS/calc