How to outline table column using JS/CSS/HTML - html

I need to select a table column on click. To show selection, I need to outline the table column.
I managed to outline each in the column needed, see pic:
However, that doesn't suit me: I need to get rid of inner lines.
CSS (actually, LESS) I currently use:
td.fd-selected
{
outline: 0.25em dashed rgb(79,115,176);
background-color: rgba(79,115,176, 0.25);
}

Unfortunately you can't do it with outline. outline is basically used to highlight a focused element in its entirety (mostly form elements). In its default setting, it uses the outline provided either by the operating system or the web browser itself (IE as example for the former, Chrome as example for the latter).
The only reliable (and the least hacky) solution is, to use borders.
Here's how (logic):
Place left and right borders to all cells.
Place top border to the appropriate cell of the first row
Place bottom border to the appropriate cell of the last row
The example below also shows, how you could highlight the header too.
Example
table{
border-collapse: collapse;
}
th {
background-color: #efefef;
}
th, td {
width: 60px;
height: 30px;
border: 1px solid #ccc;
}
td.outline {
border-left: 2px dotted #06c;
border-right: 2px dotted #06c;
}
tr:first-child > td.outline {
border-top: 2px dotted #06c;
}
tr:last-child > td.outline {
border-bottom: 2px dotted #06c;
}
/*how could it look like with the header*/
th.outline {
background-color: #99ccee;
border: 2px dotted #06c
}
<table>
<thead>
<tr>
<th></th>
<th></th>
<th class="outline"></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td class="outline"></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="outline"></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="outline"></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="outline"></td>
<td></td>
</tr>
</tbody>
</table>

Related

Problems with tables borders

I have wierd problem with my table,
As normal I want borders around my Table Heads and Table Cells,
But for some reason it only gives me a border around the whole table.
How can I fix this?
Images and code attached
How it looks
HTML;
<table width='100%'>
<tr>
<th>Maandag</th>
<th>Dinsdag</th>
<th>Woensdag</th>
<th>Donderdag</th>
<th>Vrijdag</th>
<th>Zaterdag</th>
<th>Zondag</th>
</tr>
<tr>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
</tr>
</table>
CSS;
table, th, td {
background-color: white;
border: solid black 3px;
}
The code you posted in your your question does put borders not only around the whole table, but also around every td and th.
I suppose you might not want the cells to have seperate borders. In this case you should apply the borders only to td and th (i.e. the cells) and in addition apply border-collapse: collapse; to the table itself:
table {
border-collapse: collapse;
}
th,
td {
background-color: white;
border: solid black 3px;
}
<table width='100%'>
<tr>
<th>Maandag</th>
<th>Dinsdag</th>
<th>Woensdag</th>
<th>Donderdag</th>
<th>Vrijdag</th>
<th>Zaterdag</th>
<th>Zondag</th>
</tr>
<tr>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
</tr>
</table>
The best way to approach this is to be careful with which CSS selectors you are using, and not use the table selector as a whole. For help with simple table values and alternatives, look at https://developer.mozilla.org/en-US/docs/Web/HTML/Element#table_content.
thead { background-color: white; border: solid black 3px; }
th{ background-color: white; border: solid black 3px; }
td{ background-color: white; border: solid black 3px; }
#remi03
can you try these codes
original:
bu kodları bir denermisiniz.
.baslik th{
border: solid maroon 2px;
padding: 0;
}
.icerik td{
border: solid dodgerblue 2px;
padding: 0;
}
<table width='100%'>
<tr class="baslik">
<th>Maandag</th>
<th>Dinsdag</th>
<th>Woensdag</th>
<th>Donderdag</th>
<th>Vrijdag</th>
<th>Zaterdag</th>
<th>Zondag</th>
</tr>
<tr class="icerik">
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
<td>#</td>
</tr>
</table>

Why does my table border not go all the way round the table?

I have a table with a 3px black solid border. For some reason, one cell does not display this border but only that of the internal TD. I guess I must have done something incorrectly, but cannot see where it is.
.enumeratorstable1921 {
width: 25%;
margin-left: 75px;
margin-top: 25px;
border-collapse: collapse;
font-style: normal;
border: 3px solid black;
}
.enumeratorstable1921 td {
border: 1px solid black;
height: 1.25em;
text-align: center;
}
<table class="enumeratorstable1921">
<tr>
<td colspan="4">To be filled up by the Enumerator.</td>
<td colspan="2" rowspan="2">Enumerator’s Initials.</td>
</tr>
<tr>
<td>Males.</td>
<td>Females.</td>
<td>Persons.</td>
<td>Rooms.</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
The issue seems to be caused by the unnecessary use of colspan="2" for the last cell in the top row.
There are no actual rows with 6 cells, but by using colspan=4 + colspan=2, you are making the table use 6 columns. I'm not totally sure how browsers work with rows have that fewer actual cells; it could be that they add additional placeholder cells without content.
The empty 6th cell that is (presumably) added by the browser could explain why the 5th cell of the last row is drawn using its own defined border style - because a 6th cell is added, for which the border-collapse is applied, although still in a kinda weird way.
By removing the unneeded colspan="2", the problem no longer occurs:
.enumeratorstable1921 {
width: 25%;
margin-left: 75px;
margin-top: 25px;
border-collapse: collapse;
font-style: normal;
border: 3px solid black;
}
.enumeratorstable1921 td {
border: 1px solid black;
height: 1.25em;
text-align: center;
}
<table class="enumeratorstable1921">
<tr>
<td colspan="4">To be filled up by the Enumerator.</td>
<td rowspan="2">Enumerator’s Initials.</td>
</tr>
<tr>
<td>Males.</td>
<td>Females.</td>
<td>Persons.</td>
<td>Rooms.</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>

Can't make selectors work on an html table

Wondering why selectors are not working in an html table from the css.
td {
width: 100px;
height: 100px;
}
td {
border: 1px solid black
}
tr.1 {
border-right: 1px solid black;
border-bottom: 1px solid black;
}
<table>
<tr>
<td class="1"></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
all in all i'm trying to make a tic tac toe board by showing certain borders on the 9 table spots. Can't figure out how to select just one "td" at a time to turn the borders on that I need.
Not sure if this helps but class names cannot start with a digit.
Via W3C

make one table look like two tables

I have a table that is controlled by a style sheet.
the table has been created from a poster which my boss wants it to look like. the problem i am having is on the poster there is a gap between two of the columns.
I have tried just putting two tables side by side however this caused me issues if viewed on a mobile devise, so i tried to add a column that had a border left and right and the same colour background as the rest of the page but i cant get rid of the top/bottom borders that are in place from the style sheet.
Style sheet.
.table__container {
overflow-x: scroll;
height: 100%;
width: 100%;
}
table {
border-collapse: collapse;
}
tr {
border-bottom: 0px dashed #DDD;
}
table tr th {
color: #88B53D;
}
table tr th, table tr td {
vertical-align: top;
}
.row__header {
border-top: 3px solid #DDD;
}
.row__header--day {
font-size: 1em;
text-transform: uppercase;
}
CSS on page
.nothing {
border-left: 1px solid #DDD;
border-right: 1px solid #DDD;
border-top: 0px;
border-bottom: 0px;
background-color: #eee;
}
HTML table
<div class="table__container">
<table width="100%">
<tr>
<th></th>
<th></th>
<th></th>
<td class="nothing">Gap should be here</td>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr class="row__header" style="text-align:center;">
<th class="row__header--day"></th>
<td></td>
<td></td>
<td class="nothing">Gap should be here</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
The style sheet was provided to me as part of our branding so i cant mess with it too much.
Is this the expected result? If yes then I will add some explanation.
.table__container {
height: 100%;
width: 100%;
}
table tr td.gap{
width:40%;
text-align:center;
border:none;
}
table tr td{
border:1px solid #000
}
<div class="table__container">
<table width="100%">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td class="gap"></td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td class="gap"></td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
</div>

TH not overriding table border (CSS+HTML)

I want the headings of the table to have a red solid border and the rest of the table a dotted black border.
Using the code below, all is correct but the left and right side of the TH being black dotted. Is there any way to override the <table> borders within a TH style declaration?
This is what I want to achieve:
<style type="text/css">
table {
border-style:none dotted dotted dotted;
border-collapse: collapse;
}
table th {
border: 2px solid red;
}
</style>
<table >
<thead>
<tr>
<th>title 1</th>
<th>title 2</th>
<th>title 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>text</td>
<td>text</td>
<td>text</td>
</tr>
<tr>
<td>text</td>
<td>text</td>
<td>text</td>
</tr>
<tr>
<td>text</td>
<td>text</td>
<td>text</td>
</tr>
</tbody>
</table>
A simple solution is to set the th border width equal to or larger than the table border width, if this is acceptable. For example, add
table { border-width: 2px; }
to make them equal. In your example, the width is the initial value, medium, which normally maps to 3px or 4px in browsers.
Otherwise, a different strategy is needed (see Zolthan Toth’s answer), a strategy where no left or right border is set on the table element.
The reason is that according to the [border conflict resolution][1] rules, the wider border wins (and for equal-width borders, solid beats dotted).
Try this - http://jsfiddle.net/eaTLp/
table {
border-style:none none dotted;
border-collapse: collapse;
}
table th {
border: 2px solid red;
}
table td:first-child {
border-left: dotted;
}
table td:last-child {
border-right: dotted;
}
​
You're giving the dotted border only to the bottom of the table. On the left and right you're selecting the first and last <td> in every row by :first-child and :last-child and assign them the left and right border respectively.