1

I have a simple table with styles applied via inline CSS, and it is working. But when I try to add the CSS to the document via the element, it doesn't work in Chrome. I checked the W3Schools CSS tutorials, but couldn't find a solution.

My code is this:

<!DOCTYPE html>
<html>
   <head>
      <style type="text/css">
         tr {
         border: solid 1px black; 
         padding-left: 7px; 
         padding-right: 7px;
         }
      </style>
   </head>
   <body>
      <table id="t01" style="border: 1px solid black; background-color: #E4E5E0; margin-left: 40px;">
         <tr style="border: 1px solid black;">
            <th>Available<br>On</th>
            <th>Ids</th>
         </tr>
         <tr>
            <td style="border: solid 1px black; padding-left: 7px; padding-right: 7px;"><b>Phone</b></td>
            <td style="border: solid 1px black; padding-left: 7px; padding-right: 7px;"><b>9999999
            </td>
         </tr>
      </table>
      <br><br>
      <table id="t01" style="border: 1px solid black; background-color: #E4E5E0; margin-left: 40px;">
         <tr style="border: 1px solid black;">
            <th style="border: solid 1px black; padding-left: 7px; padding-right: 7px;">Available<br>On</th>
            <th style="border: solid 1px black; padding-left: 7px; padding-right: 7px;">Ids</th>
         </tr>
         <tr>
            <td style="border: solid 1px black; padding-left: 7px; padding-right: 7px;"><b>Phone</b></td>
            <td style="border: solid 1px black; padding-left: 7px; padding-right: 7px;"><b>9999999
            </td>
         </tr>
      </table>
   </body>
</html>

https://www.w3schools.com/code/tryit.asp?filename=FIDUIS25NER6

Out put:

enter image description here

6
  • You need not specify type="text/css".Simple <style></style> would do. Commented Aug 9, 2017 at 14:28
  • Try clearing cache or open your webpage in private browsing probably your changes are not pritning Commented Aug 9, 2017 at 14:29
  • What exactly is “not working”? And why are you only showing us code that has inline styles applied and uses a style element in the head? Commented Aug 9, 2017 at 14:31
  • Inspect the DOM and see whether you actually see that style tag there. Right click and go to Inspect and then find the Elements tab. Commented Aug 9, 2017 at 14:34
  • If everything properly set, you need to clear cache data in your web browser. This also happened to me when using chrome Commented Aug 9, 2017 at 14:36

3 Answers 3

2

Change your CSS to the following. It has a typo.

<style>
     th {
     border: 1px solid black; 
     padding-left: 7px; 
     padding-right: 7px;
     }
</style>

If you want to add border to tr visit this link.

Sign up to request clarification or add additional context in comments.

Comments

0

Change this:

border: solid 1px black;

to this:

border: 1px solid black;

Comments

0
<style type="text/css">
     th {
     border: solid 1px black; 
     padding-left: 7px; 
     padding-right: 7px;
     }
 </style>

Actually in your code your are giving border to tr which does not make sense click here to know more.

So replace tr to th in your above code and it work.

code pic

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.