Farflame Farflame - 1 year ago 139
HTML Question

CSS Border, outside table border not showing

I've been using 'border = 1' in my HTML, which looks fine, but I realise it would be better to use CSS, so I created a basic border class, like so...

.basicborder table, .basicborder th, .basicborder td {
border: 1px solid black;

The borders appear around the th and td's but not around the outside of the table itself. Have I done something wrong?

Answer Source

CSS looks fine to me, but you can better use:

table.basicborder, th.basicborder, td.basicborder{border: 1px solid black;}

So, the selector starts with the least specific selector (the HTML element, instead of the class).

But it should already work fine, if you have linked your HTML properly. Do your table, th and td elements have a class="basicborder" attribute each?


If i comprehend correctly, this would be the best solution.

You make a basic style for all 's with just table,td,th{ etc... Then you add to the ones with a different style a class, lets stay differentborder.Now you make a CSS saying the following: table.differentborder, .differentborder td, .differentborder th{ your style } This selects your tables with the class, and all td's an th's where a parent has the class differentborder.

For more fun with CSS selectors you can look on the W3Schools CSS Selector Reference

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download