I have a table consisting of a header row and a couple of data rows. What I want to do is to create a blank row in between the header and the data rows, but I want this blank row to be smaller in height than the other rows (so that there isn't such a large gap).
How can I accomplish this?
My HTML mark-up code for the table is as follows:
<table class="action_table">
<tbody>
<tr class="header_row">
<td>Header Item</td>
<td>Header Item 2</td>
<td>Header Item 3</td>
</tr>
<tr class="blank_row">
<td bgcolor="#FFFFFF" colspan="3"> </td>
</tr>
<tr class="data_row">
<td>Data Item</td>
<td>Data Item 2</td>
<td>Data Item 3</td>
</tr>
</tbody>
</table>
Just add the CSS rule (and the slightly improved mark-up) posted below and you should get the result that you're after.
CSS
.blank_row
{
height: 10px !important; /* overwrites any other rules */
background-color: #FFFFFF;
}
HTML
<tr class="blank_row">
<td colspan="3"></td>
</tr>
Since I have no idea what your current stylesheet looks like I added the !important property just in case. If possible, though, you should remove it as one rarely wants to rely on !important declarations in a stylesheet considering the big possibility that they will mess it up later on.
Try this:
<td bgcolor="#FFFFFF" style="line-height:10px;" colspan=3> </td>
You don't need an extra table row to create space inside a table. See this jsFiddle.
(I made the gap light grey in colour, so you can see it, but you can change that to transparent.)
Using a table row just for display purposes is table abuse!
I know this question already has an answer, but I found out an even simpler way of doing this.
Just add
<tr height = 20px></tr>
Into the table where you want to have an empty row. It works fine in my program and it's probably the quickest solution possible.
This one works for me:
<tr style="height: 15px;"/>
I wanted to achieve the same as asked in this question but accepted answer did not work for me in May, 2018 (maybe answer is too old or some other reason). I am using bootsrap 3.3.7 and ionic v1.
You need to set line-height to do set height of specific row.
.blank_row {
line-height: 3px;
}
<table class="action_table">
<tbody>
<tr class="header_row">
<td>Header Item</td>
<td>Header Item 2</td>
<td>Header Item 3</td>
</tr>
<tr class="blank_row">
<td bgcolor="#000" colspan="3"> </td>
</tr>
<tr class="data_row">
<td>Data Item</td>
<td>Data Item 2</td>
<td>Data Item 3</td>
</tr>
</tbody>
</table>
I couldn't get anything to work until I tried this simple line:
<p style="margin-top:0; margin-bottom:0; line-height:.5"><br /></p>
which allows you to vary a filler line height to your hearts content
(I was [probably MISusing Table to get three columns (boxes) of text which I then wanted to line up along the bottom)
I'm an amateur so would appreciate comments
Related
My name is David, I am a beginner and I have some difficulties finding a solution to my problem:
I have a page with a table, on a WordPress site. The table is too big for small devices, such as mobile phones, and I would like to go from 4 columns to 2 columns for these devices. What I would like the browser to do is to "cut" the last two columns and place them just below of the first two, because the first and the third column and the second and the forth columns contain the same information.
This would be a simplifier version of the html code:
<table>
<tbody>
<tr>
<th>Artículo</th>
<th>Descripción</th>
<th>Artículo</th>
<th>Descripción</th>
</tr>
<tr>
<td>Image 1</td>
<td>International Edition ...</td>
<td>Image 2</td>
<td>Green Box</td>
</tr>
<tr>
<td>Image 3</td>
<td>Blue Box ...</td>
<td>Image 4</td>
<td>Red Box ...</td>
</tr>
<tr>
<td>Image 5</td>
<td>Absurd Box ...</td>
<td>Image 6</td>
<td>The Bigger, Blacker Box ...</td>
</tr>
</tbody>
I have thought that it may be possible to tackle this with CSS, but all the information I have found on the internet does not match exactly this problem.
Do you know how this could be done?
Thank you very much!!!!
So I have a table like so,
<table>
<tbody>
<tr>
<td colspan="6">My 6 headers</td>
</tr>
<tr>
<td colspan="6">My 6 inputs</td>
</tr>
<tr>
<td colspan="3">Indent 3 columns</td>
<td colspan="3">
<table>
<tbody>
<tr>
<td>repeating column 1</td>
<td>repeating column 2</td>
<td>repeating column 3</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
My issue is that, <td>repeating column 1</td> lines up with <td>My 4th input</td> column, but <td>repeating column 2</td> starts immediately after <td>repeating column 1</td> isntead of lining up with <td>My 5th input</td>. How can I align them?
jsFiddle: http://jsfiddle.net/pL89ykLp/
It isn't possible with nested tables unless you set the width to something fixed, and make pixel perfect corrections. This approach is highly unmaintainable.
Instead, don't use tables for layout, and use some proper semantic markup. What kind of semantic markup? That's hard to know without knowing the context of your application.
There's no need for the a nested table in the last tag. Change the second row to this:
<tr>
<td colspan="3">Indent 3 columns</td>
<td>column 1</td>
<td>repeating column 2 </td>
<td>repeating column 3</td>
</tr>
Fiddle:
http://jsfiddle.net/9ywaqf1L/
I'm trying to program a javascript timeline, in which you click on the left column revealing something in the right column. I suppose there are easier ways to do this, but the HTML below looks really really neat.
So the usual way rowspan works is that you have a td that you want to extend down a few rows to complete the table.
<tr>
<td>1942</td>
<td rowspan=2>Something happened</td>
</tr>
<tr>
<td>2017</td>
</tr>
However, what if I want to rowspan upwards, so that the below timeline item fills both rows?
<tr>
<td>1942</td>
</tr>
<tr>
<td>2017</td>
<td rowspan=2>Something else happened</td>
</tr>
I know I can just move them all to the top row and rowspan from there, but I really want to have this nice, easy-to-edit format, with dates and rows right next to each other.
(An idea I had was that if you think of rowspan as analogous to css width and height, there might be something analogous to css left and top (like "table-row"?) you could set, other than actually moving the td's to the tr you want. I don't think that exists, though.)
(also, does anyone know if negative rowspan is defined?)
No, rowspan always works “downwards”. HTML 4 does not explicitly say this, but it is definitely implied, and there is no way to change it. HTML5 makes it explicit, in its boringly detailed (but necessary for implementors) Processing model for tables.
I know this is an old question, but I was looking for this myself and this is the first result on google. After a bit of tweaking, I’ve managed to find a solution:
<table>
<thead>
<tr>
<td>Column 1/<td>
<td>Column 2</td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan=2>A1</td>
<!--This cell must be hidden; otherwise you will see a gap at the top of the second column between the header and body-->
<td style=“padding:0px;” />
</tr>
<tr>
<td rowspan=3>A</td>
</tr>
<tr>
<td>A2</td>
</tr>
<tr>
<td>A3</td>
</tr>
</tbody>
</table>
You might have to experiment a bit if you want to have a hierarchy deeper than 2 columns, but I’m confident it’s possible.
Say I have the following table:
<table>
<tr>
<td>Example</td>
</td>One</td>
</tr>
<tr>
<td>Example</td>
</td>Two</td>
</tr>
<tr>
<td>Example</td>
</td>Three</td>
</tr>
<tr>
<!--
Here I want to skip the first <td> cell; use only second. Example:
<td>(empty, possibly )</td>
<td>blah blah blah</td>
-->
</tr>
</table>
If you read my comment in the last row, you can see that in the last row I want to display something in the second column of the table, with the first remaining empty. How would I go about doing this?
As a side note, I read the question/answers in this SO question but colspan is different from what I want. I'm also not familiar with css empty-cell so if that is a solution, please provide a bit of sample code.
HTML
<tr>
<td></td>
<td>content here</td>
</tr>
CSS
table { empty-cells: show;}
Leave the <td> empty, no reason to put a space in there. can act a bit funny at times, especially in tables.
I can't see any reason not to do exactly what you are proposing: Use an empty cell containing only a ("No Break Space") in it:
<tr>
<td> </td>
<td>Whatever</td>
</tr>
CSS code:
table { empty-cells: show; }
Or, alternatively, you can insert in the <td>.
One of the answers to my previous question states that colgroup/col should work in IE only.
I've wrote an example (see below) that works on IE9 (centers cells content in the the 3rd column), but doesn't work on the latest version of Chrome.
What I did wrong?
Example of HTML:
<html>
<head><title>test table centerring</title></head>
<body>
<table border="1">
<colgroup>
<col/>
<col/>
<col align="center">
</colgroup>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Name 1</td>
<td>Value 1</td>
</tr>
<tr>
<td>2</td>
<td>Name 2, Name 2, Name 2, Name 2</td>
<td>Value 2</td>
</tr>
<tr>
<td>3</td>
<td>Name 3</td>
<td>Value 3</td>
</tr>
<tr>
<td>4</td>
<td>Name 4</td>
<td>Value 4, Value 4, Value 4, Value 4</td>
</tr>
</tbody>
</table>
</body></html>
Actually, I was pretty sure that only IE supports that, but was confused by one of the answers to question Is there any way to center certain columns in table?. The author of answer pointed also to some restrictions:
http://www.quirksmode.org/css/columns.html
Unfortunately table columns are quite hard to use, because if you use them you essentially have a table that's subdivided in two ways: by rows and by columns. The general rule is that any style defined on a row overrules any style defined on a column.
Secondly, W3C specifies that only a few declarations may be used on columns: border, background, width and visibility. Exception: IE7 and lower allow all declarations.
Thirdly, there's some confusion whether the column styles are applied to the column as a whole, or to the individual <td>s contained by it. The border declaration seems to be applied to the column as a whole, but width is applied to the individual cells.
That made colgroup/col pretty much useless for centering.