HTML table with aligned paragraphs in different cells - html

I'm trying to reproduce the following table in HTML (retrieved from a PDF):
Notice how the paragraphs on the same cell are aligned with paragraphs in other cells.
Below I show to you the table in a snippet:
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
<table style="width:50%">
<tr>
<td rowspan="2">
<p>Procedimentos</p>
</td>
<td colspan="2">
<p>Taxas (euros)</p>
</td>
</tr>
<tr>
<td>
<p>Obtenção</p>
</td>
<td>
<p>Renovação</p>
</td>
</tr>
<tr>
<td>
<p>1 —</p>
<p>2 —</p>
<p>3 —</p>
<p>4 — Produtor de semente de variedades de conservação</p>
<p>5 — Acondicionador de semente de variedades de conservação</p>
</td>
<td>
<p>...</p>
<p>...</p>
<p>...</p>
<p>200</p>
<p>150</p>
</td>
<td>
<p>...</p>
<p>...</p>
<p>...</p>
<p>30</p>
<p>15</p>
</td>
</tr>
</table>
If the paragraphs fit completely the cell without line break (remove "width" in <table>), everything is ok. However, when the table shrinks (as shown in the snippet), there is a line break and the paragraphs are no longer aligned (naturally).
I see two approaches here:
via CSS, which I don't know how.
via HTML, by subdividing the whole table such that each paragraph alignment becomes a new table row.
Option 2. is quite painful to program since I'm building these tables programatically (from PDF), which means an algorithm to subdivide the table.
Does anyone knows how to force the constraint that the paragraphs should stay aligned? Is that possible in CSS (with cross browser support)?

You need to make a <tr> for each row containing 3 <td> for each column so they stay aligned, <p> are not needed.
table, th, td {
border: 1px solid black;
border-collapse: collapse;
vertical-align: middle;
}
td {border-top: none; border-bottom: none;}
th, td {padding: 12px 16px;}
<table style="width:50%">
<tr>
<th rowspan="2"> <!-- use th for border -->
Procedimentos
</th>
<th colspan="2">
Taxas (euros)
</th>
</tr>
<tr>
<th>
Obtenção
</th>
<th>
Renovação
</th>
</tr>
<tr>
<td> <!-- use td for no border -->
1 —
</td>
<td>
...
</td>
<td>
...
</td>
</tr>
<tr>
<td>
2 —
</td>
<td>
...
</td>
<td>
...
</td>
</tr>
<tr>
<td>
3 —
</td>
<td>
...
</td>
<td>
...
</td>
</tr>
<tr>
<td>
4 — Produtor de semente de variedades de conservação
</td>
<td>
200
</td>
<td>
30
</td>
</tr>
<tr>
<td>
5 — Acondicionador de semente de variedades de conservação
</td>
<td>
150
</td>
<td>
15
</td>
</tr>
</table>

As #Heah writes, you need to put the data in separate rows. This is also better for accessibility, since it corresponds to the logical structure of the data and lets items be accessed as table cells, not as paragraphs inside a cell.
In addition, to reproduce the layout of the PDF file, you need to set borders in a more detailed manner in each direction and to reduce font size in header cells. The following does this relatively accurately, except that it does not produce the rows of dots (which are a separate issue, often asked at SO—no simple answer, but several possible approaches).
<style>
table {
width: 26em;
border: solid;
border-width: 3px 0;
border-collapse: collapse;
}
th, td {
vertical-align: bottom;
text-align: center;
border: solid 2px gray;
}
td {
border-top: none;
border-bottom: none;
}
td:first-child {
text-align: left;
text-indent: -1em;
padding-left: 1em;
}
th {
padding: 0.3em 0.4em;
font-weight: normal;
vertical-align: middle;
font-size: 80%;
}
th:first-child, td:first-child {
border-left: none;
}
th:last-child, td:last-child {
border-right: none;
}
</style>
<table>
<thead>
<tr><th rowspan="2">Procedimentos
<th colspan="2">Taxas (euros)
<tr><th>Obtenção
<th>Renovação
</thead>
<tbody>
<tr>
<td>1 —
<td>…
<td>…
<tr>
<td>2 —
<td>…
<td>…
<tr>
<td>3 —
<td>…
<td>…
<tr>
<td>4 — Produtor de semente de variedades de conservação
<td>200
<td>30
<tr>
<td>5 — Acondicionador de semente de varie­dades de conservação
<td>150
<td>15
</tbody>
</table>

Related

Indenting cells in HTML-tables

What I'm trying to achieve is the following table (which I created using Word):
Each cell basically acts as if it has two columns within it, the text-characters on the left and the digits on the right. How can I do this in HTML? The closest I have gotten is a normal table with empty cells acting as the space between the text and the digits, but that's not what I want. What's a cleaner way to do this?
If I'm understanding your intent correctly, see example below using a default auto layout and sharing a width between the wide columns to allow the skinny ones to only consume space necessary (unless you want to give them a fixed width of sorts). Though in the future a reproducible example of your effort is appreciated.
table {
table-layout: auto;
border-collapse: collapse;
border-bottom: #000 1px solid;
width: 100%;
}
th { text-align: left }
th, td {
padding: 0 .5rem;
}
table th:nth-child(odd) {
width: 50%;
border: #0f0 1px dashed;
}
table th:nth-child(2), table td:nth-child(2) {
border-right: #000 1px solid;
}
table tr:first-child {
border-bottom: #000 1px solid;
}
table tr:last-child {
border-top: #000 1px solid;
}
<table>
<tr>
<th>
wide column
</th>
<th>
skinny
</th>
<th>
wide column
</th>
<th>
skinny
</th>
</tr>
<tr>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
</tr>
<tr>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
</tr>
<tr>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
</tr>
<tr>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
</tr>
<tr>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
</tr>
<tr>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
<td>
Stuff
</td>
</tr>
</table>

How to use Html5's details and summary tag to hide and expand an entire row in a table?

I would like to use the details tag to hide and expand an entire row in a table, so I currently have the code
<table border="1">
<tr>
<td>Header 1 </td>
<td>Header 2 </td>
<td>Header 3 </td>
</tr>
<tr>
<td>Content 1 </td>
<td>Content 2 </td>
<td>Content 3 </td>
</tr>
<details>
<tr>
<td>Hidden Content 1 </td>
<td>Hidden Content 2 </td>
<td>Hidden Content 3 </td>
</tr>
</details>
</table>
When expanding the details tag, it produces the "hidden" row but in one column instead of the entire 3 columns in the original table. I have also tried putting the tag inside the row but I come accross the same issue
<tr><details>
<td>Hidden Content 1 </td>
<td>Hidden Content 2 </td>
<td>Hidden Content 3 </td>
</details>
</tr>
Has anyone also come accross this problem and managed to solve it?
Place the contents you want to hide in a new table and wrap the details tag around that:
table {
width: 300px;
}
<table border="1">
<tr>
<td>Header 1 </td>
<td>Header 2 </td>
<td>Header 3 </td>
</tr>
<tr>
<td>Content 1 </td>
<td>Content 2 </td>
<td>Content 3 </td>
</tr>
</table>
<details>
<table border="1">
<tr>
<td>Hidden Content 1 </td>
<td>Hidden Content 2 </td>
<td>Hidden Content 3 </td>
</tr>
</table>
</details>
It's invalid HTML to have <detail>s as a direct child to: <table>, <thead>, <tbody>, <tfoot>, <tr>. But , it's very valid to put anything in a <td>.
The following example has an expanded <td> with a colspan of "3" which makes it the only cell to occupy it's <tr> edge to edge and by all intents and purposes looks like a <details> as a <tr>. Within the <details> are three <section>s.
The <details> has display: table-row which will make behave as a <tr>. The three <section>s have display: table-cell -- they behave just like <td>. And finally, the <details> is wrapped in a <table> (believe it or not it's 100% valid HTML). The styles of the big <table> also apply to the mini <table>, note the content within three <section>s are perfectly 33/33/33. This is all HTML and CSS no JavaScript.
*, *::before, *::after { box-sizing: border-box; }
:root { font: 1ch/1 'Segoe UI'; }
html, body { width: 100%; min-height: 100%; margin: 0; padding: 0; }
body { display: flex; flex-flow: row nowrap; justify-content: center; align-items: center; font-size: 1.75rem; }
main { width: 100%; height: 100%; margin: 0 auto; }
table { table-layout: fixed; width: 100%; border-collapse: collapse; border: 2px inset grey; }
th, td { width: 33%; height: 30px; border: 1px solid black; }
caption, th { font-variant: small-caps; }
caption { font-size: 2.5rem; font-weight: 900; }
td::before, td::after { content: '\0a\0a\0a'; }
details { display: table-row; }
summary { font-weight: 700; cursor: pointer; }
section { display: table-cell; width: 33%; padding: 5px 3px; border: 1px solid black; }
<main>
<table>
<caption>Data Table</caption>
<thead><tr>
<th>Alpha</th>
<th>Beta</th>
<th>Gamma</th>
</tr></thead>
<tbody>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td colspan='3'>
<table>
<details>
<summary>More Nfo</summary>
<section>
Ierd lait Klarinett vu rou. Vu der Benn aremt, mä ons Halm alles Minutt. De fond rëschten schaddreg rëm. Sou un stét esou, vun fu ma'n Mier gréng. Keng schéi Gaart wee de, nei ké Ierd löschteg.
</section>
<section>
Net d'Leit iwerall schnéiwäiss de, nei main jeitzt hu. Mä Haus stét vun, as Blieder d'Kirmes dir, un frou Säiten laanscht wéi.
</section>
<section>
An kille zielen dämpen och. Hun Dall Mecht Klarinett da, dan Fuesent d'Blumme schaddreg um, all vill Gaas Hierz an. Wou d'Sonn d'Vullen hu. Mir Kënnt d'Gaassen un, wéi um botze d'Pied heescht.
</section>
</details>
</table>
</td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
</tbody>
<tfoot>
<tr><td></td><td></td><td></td></tr>
</tfoot>
</table>
</main>
I Added a summary tag to the code and seems to work.
table {
width: 300px;
}
<table border="1">
<tr>
<td>
<details>
<summary>Header 1</summary>
Hidden Content 1
</details>
</td>
<td>
<details>
<summary>Header 2</summary>
Hidden Content 2
</details>
</td>
<td>
<details>
<summary>Header 3</summary>
Hidden Content 3
</details>
</td>
</tr>
</table>

Place two cells under a header with the colspan of 1

I am struggling to put the cells containing { Lazy, Dog, Then, It } under the same header (with a colspan of 1)
I've tried creating div tags within my cell, creating 2 cells, and all the possible widths and colspan combinations I can think of.
Using div tags and CSS I can get Lazy and Dog under the header, but they are not individual cells.
<html>
<head>
<style>
table,td,tr,th{
border: 1px solid black;
}
.lazy {
float: left;
width: 50%;
}
.dog {
float: right;
width: 50%;
}
</style>
</head>
<body>
<table>
<tr>
<th>Quick</th>
<th>brown fox</th>
<th>jumps</th>
</tr>
<tr>
<td rowspan=3>over the</td>
<td><div class="lazy">lazy</div> <div class="dog">dog</div></td>
<td>and</td>
</tr>
<tr>
<td>then</td>
<td>it</td>
<td>fall</td>
</tr>
<tr>
<td colspan=2> prey to a lion </td>
</tr>
</table>
</body>
</html>
Thank you for any advice.
add colspan="2" to <th>brown fox</th>
you don't have to put div inside <td> to separate data
then edit your <td colspan=2> prey to a lion </td>
to <td colspan="3"> prey to a lion </td>
here is the working fiddle, hope it helped you
https://jsfiddle.net/LLa90017/1/
Easy as pie as follows:
table, td, tr, th {
border: 1px solid black;
}
.lazy {
float: left;
width: 50%;
}
.dog {
float: right;
width: 50%;
}
<table>
<tr>
<th>Quick</th>
<th colspan="2">brown fox</th>
<th>jumps</th>
</tr>
<tr>
<td rowspan=3>over the</td>
<td>lazy</td>
<td>dog</td>
<td>and</td>
</tr>
<tr>
<td>then</td>
<td>it</td>
<td>fall</td>
</tr>
<tr>
<td colspan=3> prey to a lion </td>
</tr>
</table>

Custom css to format tr td but not if bold detected inside td

I dont know if this is possible but...I am trying to format a table with css, to have a specific look. This is for a wordpress site that will be updated by my client. The problem is that she is going to be copying/pasting tables with a specific format, and i want the table to have that format without her doing any extra work.
This is what i have so far.
I want the cells with the Bold text to not have a dotted line bellow them.
Right now i am formating the tr lines to add the dotted lines like this:
html
<table class="dotted" border="0" width="450" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2"><strong>Argento</strong></td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong></td>
</tr>
.....
css
.dotted tr:nth-child(even) {
text-decoration: none;
border-bottom: 1px white dotted;
}
.dotted tr:nth-child(odd) {
text-decoration: none;
border-bottom: 1px white dotted;
}
Is there a way i can do this without having to add a custom class tag for each that has the bold text in it ?
This is how i want it to look like, but this is all done manually...That's what i am trying to avoid.
ps: Sometimes the tables might have more than 1 'data' under the bold letters so its not always odd, even lines, when it comes to the 'title' and the 'plays' bellow them. (this is a site for musical plays)
-Thanks
#Manoj Kumar Yeah the bold items are always under colspan 2
Since you stated the above comment, I have a CSS hack for it.
Change your CSS to have dotted border only on td instead of tr elements.
Target the elements with colspan=2 with attribute selector to have no border.
table {
background: gray;
}
.dotted td:nth-child(even) {
text-decoration: none;
border-bottom: 1px white dotted;
}
.dotted td:nth-child(odd) {
text-decoration: none;
border-bottom: 1px white dotted;
}
.dotted td[colspan="2"] { /* Attribute selector */
border: 0 none;
}
<table class="dotted" border="0" width="450" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
<tr>
<td colspan="2"><strong>Argento</strong>
</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td>Cake Box Lady</td>
<td style="text-align: right;">Postcard from Morocco</td>
</tr>
<tr>
<td colspan="2"><strong>Bellini</strong>
</td>
</tr>
</tbody>
</table>

outlook 2010 freeze column header

I'm generating HTML emails from Sql Server and some of the emails will contain a table with many, many rows. I'd like to implement frozen column headers, so that when scrolling the data (inside the email), the column header always remains visible. I've attempted many different solutions using css, to no avail. I understand Outlook won't recognize javascript - so I'm stuck with using css to do this - which I'm able to do in various web sites, but Outlook 2010 does not react the same way.
I understand the css engine in Outlook is really like going back to the days of 2001. Can anyone offer any suggestions on how to accomplish this. I'm only interested in Outlook functionality, as that is our only email vehicle.
I took a shot at using this code, which works in jsfiddle - but not in email:
<style type="text/css">
table, td {
text-align:center;
}
th {
font-weight:bold;
text-align:center;
}
table th {
padding:10px 10px 10px 10px;
border-top:0;
border-bottom:1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
background: #ededed;
}
table th:first-child {
text-align: left;
}
table tr:first-child th:first-child {
border-top-left-radius:3px;
border-left: 0;
}
table tr:first-child th:last-child {
border-top-right-radius:3px;
}
table tr {
text-align: center;
}
table td:first-child {
text-align: left;
border-left: 0;
}
table td {
padding:10px;
border-bottom:1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
background: #fafafa;
}
table tr:last-child td {
border-bottom:0;
}
table tr:last-child td:first-child {
border-bottom-left-radius:3px;
}
table tr:last-child td:last-child {
border-bottom-right-radius:3px;
}
table th, table td {
width: 160px;
}
#wrapper {
width: 740px;
height: 300px;
overflow-x: scroll;
overflow-y: scroll;
}
table thead {
position:fixed;
}
</style>
<body>
<div id="wrapper">
<table>
<!-- Table Header -->
<thead>
<tr>
<th>Task Details</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Progress</th>
<th>Vital Task</th>
</tr>
</thead>
<!-- Table Header -->
<!-- Table Body -->
<tbody>
<tr>
<td>Create pretty table design</td>
<td> </td>
<td> </td>
<td>100%</td>
<td>Yes</td>
</tr><!-- Table Row -->
<tr>
<td>Take the dog for a walk</td>
<td> </td>
<td> </td>
<td>100%</td>
<td>Yes</td>
</tr><!-- Darker Table Row -->
<tr>
<td>Waste half the day on Twitter</td>
<td> </td>
<td> </td>
<td>20%</td>
<td>No</td>
</tr>
<tr>
<td>Feel inferior after viewing Dribble</td>
<td> </td>
<td> </td>
<td>80%</td>
<td>No</td>
</tr>
<tr>
<td>Wince at "to do" list</td>
<td> </td>
<td> </td>
<td>100%</td>
<td>Yes</td>
</tr>
<tr>
<td>Vow to complete personal project</td>
<td> </td>
<td> </td>
<td>23%</td>
<td>yes</td>
</tr>
<tr>
<td>Procrastinate</td>
<td> </td>
<td> </td>
<td>80%</td>
<td>No</td>
</tr>
<tr>
<td>Hyperlink Example</td>
<td> </td>
<td> </td>
<td>80%</td>
<td>Another</td>
</tr>
</tbody>
<!-- Table Body -->
</table>
</div>
</body>
Thanks so much for any help,
Paul
Unfortunately Outlook doesn't support CSS position or overflow, so doing this in CSS looks as though it is not possible.
Because you are targeting Outlook only, you could try messing with VML. That is mostly uncharted territory, so not sure if you can find something that works. Check out backgrounds.cm for an example of how VML can be applied to a html email. Let us know how it goes if you try that route.