I have a simple need to display the cells of a table row vertically. This works just fine in FF, but not in Chrome or Safari on the Ipad.
The example below renders as expected in FF, with each row cell under each other, but in Chrome, it seems to ignore the display:block altogether.
What is the issue - or is there a better way to do this.
(The reason for wanting this is that im using @media in the CSS to render the table differently for a small screen)
for a more visual example:
A normal table might be
DATA1 | DATA2 | DATA3
but with display:block, it should be
DATA1
DATA2
DATA3
Many Thanks
<html>
<head>
<style>
table,
thead,
tr,
td
{
display:block;
}
table,tr
{
border : 1px dotted red;
}
td
{
border:1px dashed blue;
}
thead
{
display:none;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<td>Heading 1</td>
<td>Heading 2</td>
<td>Heading 3</td>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
</tbody>
</table>
</body>
</html>
The display CSS property sets whether an element is treated as a block or inline element and the layout used for its children, such as flow layout, grid or flex. Formally, the display property sets an element's inner and outer display types.
display: block An element that has the display property set to block starts on a new line and takes up the available screen width. You can specify the width and height properties for such elements. Examples of elements that are at block-level by default are <div> , <section> , <p> , and lots more.
Inline Elements: An inline element is the opposite of the block-level element.
display: inline means that the element is displayed inline, inside the current block on the same line. Only when it's between two blocks does the element form an 'anonymous block', that however has the smallest possible width.
EDIT 2:
I think I have worked out your problem. Webkit overrides display: block;
and computes it to be display: table-cell;
in a td when there is no <!DOCTYPE>
declared for your html.
To fix this I recommend you set <!DOCTYPE html>
before <html>
at the top of your html.
The reason the jsfiddle will work is because the site has a <!DOCTYPE>
already declared.
Try this and let me know if it fixes your problem. If not I'll try find another answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With