Accessible table with Vertical and Horizontal Headers - html

I'm working on a table that looks similar to my example below where X's in cells denote certain criteria based on the intersection of the respective horizontal/vertical headings.
For instance, in this situation an orange would have the qualities of "sweet" and "sour" but not salty or bitter.
<table>
<tr>
<th></th>
<th scope="col">Sweet</th>
<th scope="col">Sour</th>
<th scope="col">Salty</th>
<th scope="col">Bitter</th>
</tr>
<tr>
<th scope="row">Apple</th>
<td>x</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Orange</th>
<td>x</td>
<td>x</td>
<td></td>
<td></td>
</tr>
</table>
What would be the appropriate way to mark this up so that it is semantic and accessible? It seems as if cells should contain something more extensive than just an "X" to be meaningful, even if visually it just shows an "X".
Also, should the visibly empty cells actually contain some visually hidden text that states that said cell is not applicable?

I would assume that "Yes" and "No" are great indicators, but do require some context (i.e scrolling to the heading of the table)
Having the text "sweet" "sour" "salty" or "bitter" is also an evident choice that would perfectly fit.
Everybody hates ticks in a consecutive table columns which do require a lot of attention.
<table>
<tr>
<th scope="row">Apple</th>
<td>Sweet</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Orange</th>
<td>Sweet</td>
<td>Sour</td>
<td></td>
<td></td>
</tr>
</table>

Related

Adding multiple elements in a table column

I am trying to add multiple table cells elements under each of my heading cells but it isn't working.
Here is a screen for better understanding :
I would like to have for each of my category, say for example,
Category 1 : to have below "Brandon" others names like => Steph, Emily, John, etc.
So far I made with a line break but it doesn't work as expected: each item should be in a separated row.
<table>
<tr>
<th>Category 1</th>
<th>Category 2</th>
</tr>
<tr>
<td>Emil<br>Brandon</td>
<td>Tobias</td>
</tr>
</table>
Simply add another row.
<table>
<tr>
<th>Category 1</th>
<th>Category 2</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
</tr>
<tr>
<td>Brandon</td>
<td></td>
</tr>
</table>

Adding flags into tables dynamically

I was wondering if it is possible to add flags to the table dynamically. The countries listed below are just for examples but I want them to come out of a list and it should add the country flags dynamically next to a 3 char country code.
<table>
<thead>
<tr>
<th>Flag</th>
<th>Country</th>
</thead>
<tbody>
<tr>
<td></td>
<td>USA</td>
</tr>
<tr>
<td></td>
<td>GER</td>
</tr>
<tr>
<td></td>
<td>CHI</td>
</tr>
</tbody>
</table>
If it is possible, can someone help me, point me in a direction from which I can find a solution to this?

Adding data only in last column of a row and keeping preceeding cells empty

Here is what I have done to make a calendar. How can I do it other way if possible without having these empty <td> tags because when I apply hover CSS to data cells empty cells too get showed and behave like non-empty data cells.
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>1</td>
</tr>
You can use colspan like this
<tr>
<td colspan="7">1</td>
</tr>
This will create a single <td> with width equal to 7<td>s
The syntax is
<td colspan="number">
where number specifies the number of columns a cell should span.
Read more about it here
UPDATE
If you need to set 1 just for sunday, then you'll have to do it like this
<tr>
<td colspan="6">1</td>
<td>1</td>
</tr>

Html table with yes/no data?

I need to create an HTML table for a website that has binary yes/no data. I also need a 'yes' to be styled with a tick.
For instance Billy does have a drivers licence, but does not live in London. I need my table to look like this:
Is this a semantically correct solution?
http://jsfiddle.net/
<table>
<thead>
<tr>
<th>Name</th>
<th>Has drivers licence?</th>
<th>Lived in London?</th>
</tr>
</thead>
<tbody>
<tr>
<td>Billy</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td>Alex</td>
<td></td>
<td>Yes</td>
</tr>
<tr>
<td>John</td>
<td>Yes</td>
<td></td>
</tr>
</tbody>
</table>
Would it still be semantically correct to use ✓ instead of 'Yes'? I need this data to be editable by the CMS so I cant style the tick with a CSS class.
You could use the abbr tag, to describe the ✓ for screenreaders..
<td><abbr title="Yes">✓</abbr></td>
Here is another Question concerning this issue:
How to target a braille / screen-reader via CSS

strucure of component inside table html

I want to make a table of orders, for each row there's an arrow that show a bill details related to each order and hide when I click again on the button.
How can I make the structure of the table?
I make like this
<table id="customerTable">
<thead>
<tr>
<td>customer name </td>
<td>order date</td>
<td>sale point</td>
<td>total</td>
</tr>
</thead>
<tr>
<td>customer name </td>
<td>order date</td>
<td>sale point</td>
<td>total</td>
<td>show details</td>
</tr>
//also loop here as the number of bills
<tr>
<td>bill order/td>
<td>product</td>
<td>price</td>
</tr>
I don't think like this structure is correct, and making div inside a table doesn't work, any suggestion please?
Possible structure:
<table id="customerTable">
<thead>
<tr>
<td>customer name </td>
<td>order date</td>
<td>sale point</td>
<td>total</td>
<td></td>
</tr>
</thead>
<tbody>
<tr class="master">
<td>customer name </td>
<td>order date</td>
<td>sale point</td>
<td>total</td>
<td>
show details
</td>
</tr>
<tr class="detail">
<td colspan=5>
<!-- new <table> with your details of this row -->
</td>
</tr>
<!-- ... more rows ... --->
</tbody>
</table>
Example: http://jsfiddle.net/J7szf/
Example 2: http://jsfiddle.net/J7szf/1/
You can probably use a popup near the "Show Details" Link
Example : http://jsfiddle.net/vdcUA/93/
If you want the content to be displayed in the table itself , provide here some idea on how u want the content displayed
In your example, you have an extra unneeded <tr> before your loop. You should have a standard table structure but hide / show the details depending on a click.
You'd better use:
styling with css and classes the standard row and the details
using js to hide / show rows
Actually, you could use jquery plugins to do this kind of stuff. See this example of datatables grouping rows
Jqgrid can also make some row grouping
[EDIT] The easiest way to define your HTML structure is to get inspired from the HTML in these jquery plugin examples