2

I have the following line of code in my html page & table doesn't show up borders

 <table style="{border-color: black;padding-left:2px;border-style: solid;border: 5px;border-width: 2px; }">

Can you help me debug that.

1
  • remove brackets .. and for testing css chrome developers console can come in handy .. Commented Jul 10, 2014 at 6:29

4 Answers 4

2

In addition to the unnecessary braces, the border CSS needs a little love. Try this instead:

<table style="padding-left:2px; border: 5px solid black;">
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to hear it helped! If this answer or any other one solved your issue, please mark it as accepted. Thank you.
2

Syntax error. Remove { and }

<table style="border-color: black;padding-left:2px;border-style: solid;border: 5px;border-width: 2px;">

Also no need to write border-color, border-style and border-width separately. You can combine and simplify like below.

 border:2px solid black;

So you can update your code like this.

<table style="border:2px solid black; padding-left:2px;">

Comments

0

There are several issues involved:

  • The curly braces { and } make the code invalid and cause it to be skipped. Remove them. Reference: CSS Style Attributes.
  • The shorthand border notation always sets all border properties, using initial values as defaults. Thus, border: 5px sets border-style to none (and border-color to the value of the color property). The simplest fix is to remove that declaration; it seems to be meant to set border width, but used this way it has undesired side effects, and besides you are setting the width in later declaration (to a different value).
  • Even when fixed, the code sets a border on the table as a whole only, not on its cells, and you might have meant to set borders on cells too. There is no way to do that in a style attribute of the table element; you need to set them in style attributes of cell elements or (better) in a style element or (even better) in a linked style sheet.

The minimally fixed code that deals with the first two issues is:

<table style="border-color: black;padding-left:2px;border-style: solid;
border-width: 2px">

Comments

0

Try this:

JSFIDDLE

Your Code:

<table id="table" style="border-color: black;padding-left:2px;border-style: solid;border: 5px solid black;">

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.