Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

HTML & CSS why is my css for boders not being called for table id #t01

HTML:
<!DOCTYPE html>

<html>

<head>

<title> This is a title</title>

<style>

#t02, th, td {

  border: 1px solid black;

  border-collapse: collapse;

}

th, td {

   padding: 10px;

}

th {

  text-align: left;

}

#t01 {

  background-color:black;

  color: white;

  width: 100%;

  text-aligh: left;

  border: 1px solid white;



}



</style>

</head>

<body>

<h2> Basic HTML Table </h2>

<table style="width:100%;">

<caption><b> Members and Age<b> </caption>

<tr>

<th> First Name </th>

<th> last Name </th>

<th colspan="2"> Age </th>

</tr>

<tr>

<td> TEST</td>

<td> TEST</td>

<td> 60 </td>

<td></td>

</tr>

<tr>

<td> TEST</td>

<td> TEST</td>

<td> 49 </td>

<td> </td>

</tr>

<tr>

<td> TEST</td>

<td> TEST</td>

<td> 27 </td>

<td></td>

</tr>

<tr>

<td> TEST</td>

<td> TEST</td>

<td> 25 </td>

<td></td>

</tr>

<tr>

<th></th>

<th></th>

<th rowspan="2">sub-total<hr>total</th>

<td> 161 </td>

</tr>

<tr>

<td></td>

<td></td>

<td> 161</td>

</tr>

</table>

<br>

<br>

<br>

<table id="t01">

<tr>

<th>First Name</th>

<th> Last Name </th>

<th> Age </th>

</tr>

<tr>

<td> TEST</td>

<td> TEST</td>

<td> 23</td>

</tr>

</table>

</body>

</html>
 
Last edited by a moderator:
Hey And welcome 😀

The answer to your question is, it is 😀 your telling the table to have a border and not the cells. I have also fixed some of your code that was giving you some issues too and changed the css to do what you was after 😀 and you can find them below via the link 😀


Code:
<html>
  <head>
    <style>
      #t02, th, td {
      border: 1px solid black;
      border-collapse: collapse;
      }

      th, td {
      padding: 10px;
      }

      th {
      text-align: left;
      }

      #t01 th,#t01 td {
      background-color: black;
      color: white;
      width: 100%;
      text-align: left;
      border: 1px solid white;
      }
    </style>
  </head>
  <body>
    <h2> Basic HTML Table </h2>

    <table style="width:100%;">
    <caption>
      <b> Members and Age</b>
    </caption>
      <tr>
        <th> First Name </th>
        <th> last Name </th>
        <th colspan="2"> Age </th>
      </tr>
      <tr>
        <td> Naresh</td>
        <td> Prasad</td>
        <td> 60 </td>
        <td></td>
      </tr>
      <tr>
        <td> Vijaylaxmi</td>
        <td> Devi</td>
        <td> 49 </td>
        <td> 51 </td>
      </tr>
      <tr>
        <td> Nidhi</td>
        <td> Gupta</td>
        <td> 27 </td>
        <td></td>
      </tr>
      <tr>
        <td> Aaditya</td>
        <td> Gupta</td>
        <td> 25 </td>
        <td></td>
      </tr>
      <tr>
        <th></th>
        <th></th>
        <th rowspan="2">sub-total<hr>total</th>
        <td> 161 </td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td> 161</td>
      </tr>
    </table>
    <br>
    <br>
    <br>
      <table id="t01">
        <tr>
          <th>First Name</th>
          <th> Last Name </th>
          <th> Age </th>
        </tr>
        <tr>
          <td> Aaditya</td>
          <td> Gupta</td>
          <td> 23</td>
        </tr>
      </table>
  </body>
</html>
 

Latest posts

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom