Why is tab keyboard navigation not working with tabIndex set? - html

Consider this HTML table:
<table contenteditable="true">
<tbody>
<tr>
<td tabindex="0"></td>
<td tabindex="0"></td>
<td tabindex="0"></td>
</tr>
<tr>
<td tabindex="0"></td>
<td tabindex="0"></td>
<td tabindex="0"></td>
</tr>
</tbody>
</table>
I would like the user to be able to tab from cell to cell as he edits the table contents, and to programmatically focus on any given cell. I observed the following behaviors in Chrome, and I'm trying to understand and remedy them:
I don't understand why if I put the cursor in one cell and press the tab key, the cursor doesn't go to the next cell.
I don't understand why when I click on a cell, although the cursor shows up and I can edit its contents, focus still seems to be on the table as a whole rather than that cell specifically (found out by console logging document.activeElement)
I don't understand why when I execute myCell.focus() in Javascript, the cursor doesn't appear in the cell in question even though the cell becomes the activeElement and the table as a whole has contenteditable="true"
JSFiddle example

For tabbing to work on both Chrome 76 and Firefox 68, I needed to set the table itself to not be editable, but then also set each cell to be editable:
<table contenteditable="false">
<tbody>
<tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
<tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
</tbody>
</table>
JSFiddle example

It will be better to use input elements in each tds and then use this function:
js
$('td').bind('keypress', function(event) {
if(event.which === 9) {
if ($(this).next().length > 0){
$(this).next().find("input").focus();
}else{
$(this).parent().next().find('td').first().find("input").focus();
}
});
html
<table contenteditable="true">
<tbody>
<tr>
<td tabindex="0"><input /></td>
<td tabindex="0"><input /></td>
<td tabindex="0"><input /></td>
</tr>
<tr>
<td tabindex="0"><input /></td>
<td tabindex="0"><input /></td>
<td tabindex="0"><input /></td>
</tr>
</tbody>
</table>

Related

Setting <td> width throwing off table display?

I'm totally stuck trying to figure out why setting a td width attribute in the following table is throwing off the display.
<table style="width:100%;">
<tbody>
<tr>
<td colspan="4">
<big><big><b>Investments By Bruce Wayne</b></big></big>
</td>
</tr>
<tr>
<td style="width:20%;"><b><u>Date</u></b></td>
<td style="width:20%;"><b><u>Invested</u></b></td>
<td style="width:30%;"><b><u>Company (and Round)</u></b></td>
<td style="width:30%;"><b><u>SPV</u></b></td>
</tr>
</tbody>
</table>
The above is rendered with the word "Invested" outside of the table entirely (see screenshot).
Any thoughts on why this might be happening? Thanks in advance!
<table style="width:100%;">
<tbody>
<tr>
<td colspan="4">
<big><big><b>Investments By Bruce Wayne</b></big></big>
</td>
</tr>
<tr>
<td style="width:20%;"><b><u>Date</u></b></td>
<td style="width:20%;"><b><u>Invested</u></b></td>
<td style="width:30%;"><b><u>SPV</u></b></td>
<td style="width:30%;"><b><u>Company (and Round)</u></b></td>
</tr>
</tbody>
</table>
Problem:
All you have to do is to format your code. There is a NON-BREAKING-SPACE between td and style <td style (the one with the Investment text) that destroys the layout. To reproduce you can delete the whitespace and add the whitespace again.
Note:
You have to <big><big> there wrapped - this can be reduced to just one element.
<table style="width:100%">
<tbody>
<tr>
<td colspan="4">
<big><b>Investments By Bruce Wayne</b></big>
</td>
</tr>
<tr>
<td style="width:20%;"><b><u>Date</u></b></td>
<td style="width:20%;"><b><u>Invested</u></b></td>
<td style="width:30%;"><b><u>Company (and Round)</u></b></td>
<td style="width:30%;"><b><u>SPV</u></b></td>
</tr>
</tbody>
</table>

Repeat HTML table-footer on every printed page

In my body i have a table element (like this below).
When i want to print my html page, there should be the and content on every page. The header is working great but the footer is only showed at the last page.
I have found many "solutions" for a problem like this but none worked
Adding or removing --style="display: table-footer-group"-- to the element does nothing.
It is imported to use only HTML and CSS
<table>
<thead>
<tr>
<td colspan="5">
<table style="width: 100%;">
<tr>
<td>Some Header Stuff</td>
</tr>
</table>
</td>
</tr>
<tr class="border_bottom">
<td colspan="1" class="styledheader">header1</td>
<td colspan="1" class="styledheader">header2</td>
<td colspan="1" class="styledheader">header3</td>
<td colspan="1" class="styledheader">header4</td>
<td colspan="1" class="styledheader">header5</td>
</tr>
</thead>
<tfoot>
<tr class="border_top">
<td colspan="1">Footer Left</td>
<td colspan="4">Footer Right</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>SomeText</td>
<td>SomeText</td>
<td>SomeText</td>
<td>SomeText</td>
<td>SomeText</td>
</tr>
---More rows
</tbody>
</table>
--- Edit 12.05.2017 09:45
-- Changed code as creativename & daviddomain wrote
Changed
<td colspan="1" id="styledheader">header1</td>
to
<td colspan="1" class="styledheader">header1</td>
and made first "/tbody" to "tbody"
You're probably using chrome. According to https://crbug.com/656232 (While table header prints in all pages, table footer only appears in last page) Edge and Firefox do what you want you want, but chrome support is in progress.
So, until chrome gets that bug fixed, use a different browser.
You are not opening the tbody with the <tbody> tag. Also use classes instead of id's when using it more than once:
<td colspan="1" class="styledheader">header1</td>
<td colspan="1" class="styledheader">header2</td>
instead of
<td colspan="1" id="styledheader">header1</td>
<td colspan="1" id="styledheader">header2</td>
Don't forget to change the id selector to a class selector in your CSS

Setting up colspan in HTML table

Having some trouble figuring out what the grid is like for using colspan, so that I can evenly align my items.
HTML
<table class="table MethodList" ng-repeat="method in api.methods">
<tr>
<td colspan=4 style="font-weight:bold">{{method.name}}</td>
<td colspan=8>{{method.desc}}</td>
<tr>
<td colspan=4></td>
<td colspan=8 style="background:#E6E6DA">{{method.parameters}}</td>
</tr>
<tr>
<td colspan=4></td>
<td colspan=8>{{method.additional}}</td>
</tr>
</tr>
</table>
What this does
As you can see, the following texts are pushed back each row further and I do not know why. I am trying to just keep the initial value (index, create, confirm, choose) as the only item in colspan=4, then everything else to be after that.
I also have bootstrap included in case they use some nice template.
It looks like you have a misplaced closing tr tag </tr> at the end of your table.
Please fix it and check again to see if the layout is displayed correctly
Your code should became something like this:
<table class="table MethodList" ng-repeat="method in api.methods">
<tr>
<td colspan=4 style="font-weight:bold">{{method.name}}</td>
<td colspan=8>{{method.desc}}</td>
</tr>
<tr>
<td colspan=4></td>
<td colspan=8 style="background:#E6E6DA">{{method.parameters}}</td>
</tr>
<tr>
<td colspan=4></td>
<td colspan=8>{{method.additional}}</td>
</tr>
</table>

HTML complex tables

i want to;
1.remove a small part of this table and make a free space there.i comennted it on the code.
2.also to center the words in the table.
CAN ANY ONE HELP ME PLEASE?(Please use only HTML not css or javascript)
<html>
<head>
<title>My First Webpage</title>
</head>
<body >
<table border="1px" width="80%" cellspacing="0" cellpading="0" >
<tr>
<td ></td> <! -- I NEED TO REMOVE THIS PART FROM TABLE AND MAKE A **FREE SPACE** HEARE -->
<td >9-11</td>
<td >11-13</td>
<td >13-15</td>
<td >15-17</td>
</tr>
<tr>
<td >Monday</td>
<td>6</td>
<td colspan="0">7</td>
<td rowspan ="3">Lunch</td>
<td>a</td>
</tr>
<tr>
<td>Tuesday</td>
<td colspan="2">< free</td>
<td>s</td>
</tr>
<tr>
<td >Wedensday</td>
<td>a</td>
<td>s</td>
<td>5</td>
</tr>
</table>
</body>
</html>
It's best practice to use CSS for the centering. You could do it like this:
<table style="text-align:center">
But you could also use HTML in each cell like this:
<td align="center">Text</td>
or like this:
<td><center>Text</center></td>
Tables aren't meant to skip cells, so different browsers will handle it differently. You won't get consistent results. Depending on what you need the blank space for, though, there are some workarounds you could use.
If you just want the cell to be empty, put a sticky space inside like this:
<td> </td>
Some browsers are confused by empty tags, but adding a sticky space (which displays as a space- you can't see it) fixes that.
If you want the cell to have no background / border, so it looks like it isn't there:
<td style="background:none; border:none">
That's embedded CSS, and I've included it because the HTML version is deprecated and you're really supposed to use CSS instead, but here's the HTML:
<td bgcolor="#000000" border=0>
You must replace #000000 with the color behind the table. If there's an image or text behind the table, you could use a transparent image as the background instead. (I wouldn't advise going to all that trouble if there's any way you can use style="background:none" instead, though.)
You could make the cell following the one you're removing span the space of both of them:
<td colspan=2>9-11</td>
<td >11-13</td>
<td >13-15</td>
<td >15-17</td>
Another solution is to put tables inside a table.
<table border="1px" width="80%" cellspacing="0" cellpading="0" >
<tr>
<td align="right"> <!-- The content is aligned to the right so that the blank space will be on the left. -->
<table width="80%"> <!-- The width of four out of five cells is 80% of the total width -->
<tr>
<td >9-11</td>
<td >11-13</td>
<td >13-15</td>
<td >15-17</td>
</tr>
</table>
</td>
</tr>
<tr>
<td >Monday</td>
<td>6</td>
<td colspan="0">7</td>
<td rowspan ="3">Lunch</td>
<td>a</td>
</tr>
<tr>
<td>Tuesday</td>
<td colspan="2">< free</td>
<td>s</td>
</tr>
<tr>
<td >Wedensday</td>
<td>a</td>
<td>s</td>
<td>5</td>
</tr>
</table>
As you can see, there are a ton of different ways to approach the problem. HTML leaves a lot of room for experimentation and creativity.
jF: http://jsfiddle.net/theStudent/b9tGV/1/
I would say you will have to use some CSS, that would be the most professional way to go about doing it.
I have started you off so you can see how that works in above link, it is quite simple and there is lot of tutorials and samples online just do little research.
Sample I started you with is very plain needs more work.
best of luck I believe that is a good start
HTML
My First Webpage
<body >
<table width="80%" cellspacing="0" cellpading="0" >
<tr>
<td class="no-border"></td> <! -- I NEED TO REMOVE THIS PART FROM TABLE AND MAKE A **FREE SPACE** HEARE -->
<td class="border">9-11</td>
<td class="border">11-13</td>
<td class="border">13-15</td>
<td class="border">15-17</td>
</tr>
<tr>
<td class="border">Monday</td>
<td>6</td>
<td colspan="0" class="border">7</td>
<td rowspan ="3" class="border">Lunch</td>
<td class="border">a</td>
</tr>
<tr>
<td class="border">Tuesday</td>
<td class="border" colspan="2">< free</td>
<td class="border">s</td>
</tr>
<tr>
<td class="border">Wedensday</td>
<td class="border">a</td>
<td class="border">s</td>
<td class="border">5</td>
</tr>
</table>
</body>
</html>
CSS
.no-border{
border: none;
}
.border{
border: 1px solid #000;
text-align:center;
}

colspan issue in Chrome

When using colspan on a cell, cell takes width of cell above instead of entire row when in Chrome. Works fine in IE. Even putting 100% width on cell doesn't change anything.
<table cellspacing="1px" cellpadding="0" border="0" id="shiftData">
<tr>
<td class="topRow">Employee</td>
<td class="topRow">Working For</td>
<td class="topRow">Shift</td>
<td class="topRow">Date</td>
<td class="topRow">Time</td>
</tr>
<tr>
<td>Audrey W</td>
<td>Justin B</td>
<td>Host</td>
<td>6/14/12</td>
<td>4:00pm</td>
</tr>
<tr><td colspan="5" align="right" class="buttonRow"><a class="approve" href="">Approve</a><a class="deny" href="">Deny</a></td></tr>
<tr>
<td>Justing B</td>
<td>Leigh Anne</td>
<td>Dishwasher</td>
<td>6/16/12</td>
<td>11:00am</td>
</tr>
</table>
I had a float: right; on the cell div that was apparently causing the issue in Chrome.