html doctype adds whitespace?

六眼飞鱼酱① 提交于 2019-11-28 08:38:59

As you can see in this table, the first Doctype triggers quirks mode in all browsers, the second will trigger standards mode.

The rest of this story is continued at Images, Tables, and Mysterious Gaps:

Setting images to be blocks

The first choice, and one that will work for most graphically-intense designs, is to convert the image from being an inline element to a block-level element. Do that, and it no longer generates a line box, and so the problem goes away-- assuming that the image is the only thing that occupies that table cell. In the simplest case, we might add a style like this:

td img {display: block;}

My suspicion is that the white space within the markup (e.g., the newlines and tabs that make the table code nicely legible) are at fault. I've encountered similar issues before, where space in the markup resulted in annoying space on the screen, even where it would appear not to matter (e.g., between <li> tags).

Try collapsing the table markup onto a single lengthy line.

Not sure why the space occurs. As far as a fix goes, if you don't mind explicitly setting a height for your table cell, you can add display:block; and height:60px; to your td styles.

The first DOCTYPE will render your page in almost standards mode:

"Almost standards" mode rendering matches "standards" mode in all details except for one. The layout of images inside table cells is handled the same way "quirks" mode operates.

The second DOCTYPE will render your page in standards mode.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!