HTML5的!doctype搞砸了我的风格

时间:2013-08-10 14:44:40

标签: html5 styles doctype

我目前正在制作一些简单的图库,它应该显示固定大小为148px的缩略图。

当我在文件的最开头指定<!doctype html>时,它会弄乱我的风格,使其看起来像这张照片。

How it should look

没有这一行(我猜浏览器正在以HTML4模式工作),它看起来是正确的:

Hot it actually looks

自己看看文件:http://ablage.stabentheiner.de/2013-08-10_gallery.html

新文件版本:http://ablage.stabentheiner.de/2013-08-10_gallery2.html具有不同文档类型的同一文件:http://ablage.stabentheiner.de/2013-08-10_gallery2_html4.html

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Gallerie</title>
<base target="Hauptframe">
<style>
body {
    background-color: #CCFFCC;
    background-image:url(../background.gif);
}
table {
    border:none;
    border-spacing:0;
}
img {
    border:none;
}
A:hover {
    color: #FF0000; 
    font-weight: bold
}
.imagefloat {
    border: medium solid #FFF;
    float: left;
    margin-top: 0px;
    margin-right: 16px;
    margin-bottom: 20px;
    margin-left: 0px;
}
.nowrap {
    text-align: center;
    font-family: Arial, Helvetica, sans-serif;
    font-style: italic;
    font-size: 16px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    margin-left: 0px;
}
.nowrapline2 {
    font-size: 12px;
}
.nowrapline3 {
    font-size: 10px;
}
.error {
    font-weight: bold;
    color: #F00;
}
.caption_cell {
    background-color: #FFF;
    width: 148px;
    height: 80px;
}
</style>
</head>

<body>


<div class="imagefloat">
    <table>
        <tr>
            <td><a href=""><img src="http://placehold.it/148x148" width="148" height="148" alt=""></a></td>
        </tr>
        <tr class="caption_cell">
            <td>

            <p class="nowrap">Title</p><p class="nowrap nowrapline2">Subtitle</p><p class="nowrap nowrapline3">Copyright</p>
        </td>
        </tr>
    </table>
</div>


<div class="imagefloat">
    <table>
        <tr>
            <td><a href=""><img src="http://placehold.it/148x148" width="148" height="148" alt=""></a></td>
        </tr>
        <tr class="caption_cell">
            <td>

            <p class="nowrap">Title</p><p class="nowrap nowrapline2">Subtitle</p>
        </td>
        </tr>
    </table>
</div>

</body>

2 个答案:

答案 0 :(得分:1)

好的,你的问题很简单:你没有使用有效的HTML5。您应该始终检查的第一件事是您的代码validates as well-formed HTML,而您的代码不是。之后,检查你的CSS;但请注意,如果问题是您的网站在HTML4模式下显示的效果比HTML5模式更好,那么这不是一个错误,这意味着您在编写代码时做错了。

这里的第一步是修复W3C验证器指出的所有故障;如果这不能解决问题,那么再看看你的CSS。

答案 1 :(得分:1)

解决方案很简单。默认情况下,图像作为内联对象处理。对于内联渲染,通常需要行之间的最小垂直间隙,这是浏览器添加的,以提高可读性。要删除此额外间隙,请尝试对这些图像应用“display:block”。

相关问题