Newbie CSS Table Grid Lines Question

Discussion in 'CSS' started by hemanthjava, Sep 6, 2011.

  1. #1
    Hi,

    My Table is not showing internal Gridlines for rows and Columns. Need some help on making them appear.

    My CSS

    table{
    	background: lightgrey;
    	border-style: solid;
    	border-width: 1;
    	border-color: black;
    }
    
    th{
    	background: grey;
    	font-weight: bold;
    	padding: 5px;
    }
    
    
    
    td{
    	padding: 5px;
    }
    
    td.code{
    	font-family: courier, courier-new, serif;
    	font-weight: bold;
    }
    Code (markup):
    My HTML (Just the Table Code)

    <table>
      <tr>
        <th>Property</th>
        <th>Purpose</th>
      </tr>
      <tr>
        <td class="code">font-family</td>
        <td>Specifies the font used.</td>
      </tr>
      <tr>
        <td class="code">font-size</td>
        <td>Specifies the size of the font used.</td>
      </tr>
      <tr>
        <td class="code">font-style</td>
        <td>Specifies whether the font should be normal, italic or oblique.</td>
      </tr>
      <tr>
        <td class="code">font-weight</td>
        <td>Specifies whether the font should be normal, bold, bolder, or lighter</td>
      </tr>
    </table>
    Code (markup):
    I have attached the screenshot of how it looks on my Browser. You can see that the internal Grid Lines don't appear. What could be missing.

    Thanks,
    Hemanth
     

    Attached Files:

    Solved! View solution.
    hemanthjava, Sep 6, 2011 IP
  2. eCollector

    eCollector Active Member

    Messages:
    197
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hello.

    Here is the solution:

    CSS
    
    table{
    	background: lightgrey;
    	border-style: solid;
    	border-width: 1;
    	border-color: black;
    	border-collapse: collapse;
    }
    
    th{
    	background: grey;
    	font-weight: bold;
    	padding: 5px;
    	border-style: solid;
    	border-width: 1;
    	border-color: black;
    }
    
    
    
    td{
    	padding: 5px;
    	border-style: solid;
    	border-width: 1;
    	border-color: black;
    }
    
    td.code{
    	font-family: courier, courier-new, serif;
    	font-weight: bold;
    }
    
    Code (markup):
    HTML
    
    <table cellpadding="0" cellspacing="0">
      <tr>
        <th>Property</th>
        <th>Purpose</th>
      </tr>
      <tr>
        <td class="code">font-family</td>
        <td>Specifies the font used.</td>
      </tr>
      <tr>
        <td class="code">font-size</td>
        <td>Specifies the size of the font used.</td>
      </tr>
      <tr>
        <td class="code">font-style</td>
        <td>Specifies whether the font should be normal, italic or oblique.</td>
      </tr>
      <tr>
        <td class="code">font-weight</td>
        <td>Specifies whether the font should be normal, bold, bolder, or lighter</td>
      </tr>
    </table>
    
    Code (markup):
     
    eCollector, Sep 7, 2011 IP
  3. hemanthjava

    hemanthjava Well-Known Member

    Messages:
    1,258
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Thanks a lot. It worked well. It works on Internet Explorer but not on Chrome.

    When I changed the border-width: 1; to border-width: 1px; for each of the selectors then it worked. Could you please tell me the reason?

    Also Could you please also explain why the border-collapse: collapse; was used. I am new to this. When I removed it the Borders looked very wide.

     
    Last edited: Sep 7, 2011
    hemanthjava, Sep 7, 2011 IP
  4. #4
    I don't know what caused the issue on Chrome (to be honest I didn't check in other that FF as I was in a hurry :) )but I'm glad you solved it.

    I usually always put px/em/% automatically so I never really encountered that problem.

    Border-collapse is used to merge borders from each cell (<td></td>) in one. Without that your 1px border would be 2px wide as each cell would have own border.
    This way we merged them in one.

    Hope that helps.
     
    eCollector, Sep 7, 2011 IP