Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

css - Display:Block not working in Chrome or Safari

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...