1

我制作了一个网站,在主 div 上显示多个 div(作为内联元素),这些 div 包含一个 IMG 和 P 元素。

好吧,如果我留下 P 元素(或没有 p 标签的文本),一切正常,但如果我在 img 后添加文本,则对应的 div 会脱离正常位置。

该页面位于http://ace-acid.no-ip.org/acid-game-studios/ (即工作版本)

而这个是有问题的版本-> http://ace-acid.no-ip.org/acid-game-studios-issue/ (在这里你可以清楚地看到所有没有文本的div它,有间隔的下行空间......)

我怎样才能防止这种行为?

谢谢大家^^

<编辑>

我认为这是一个 css 问题(块元素,内联块元素,fextflow,垂直对齐,...)不是吗?

顺便说一句 -> 该网站是一个基于流体网格的网站,因此如果您缩小浏览器,它将显示一个桌面版本和一个移动版本。问题似乎只出现在文本所在的同一行,因为在下一行中,div-blocks 没有间隔下来......

</编辑>

HTML 代码:

<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>aCID Game Studios</title>
<link rel="stylesheet" type="text/css" href="boilerplate.css">
<link rel="stylesheet" type="text/css"href="style.css">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="respond.min.js"></script>
</head>
<body>
<div class="gridContainer clearfix">
    <div id="div_header" align="center">
        <div id="div_header_img"></div>
        <div id="div_menu" align="center">
            <p>&lt; MENU &gt;</p>
        </div>
    </div>
    <div id="div_main" align="center">
        <div id="div_page">
            <br><br><p>&lt; PAGE &gt;</p><br><br>
            <div class="div_game_thumb">
                <img style="vertical-align:middle" src="img/games/LegendOfAce.png" onMouseOver="this.src='img/games/LegendOfAce_hover.png'" onMouseOut="this.src='img/games/LegendOfAce.png'"/>
            </div>
            <div class="div_game_thumb">
                <img src="img/games/GunsOfTheNation.png" onMouseOver="this.src='img/games/GunsOfTheNation_hover.png'" onMouseOut="this.src='img/games/GunsOfTheNation.png'"/>
            </div>
            <div class="div_game_thumb">
                <img src="img/games/LegendOfAce.png" onMouseOver="this.src='img/games/LegendOfAce_hover.png'" onMouseOut="this.src='img/games/LegendOfAce.png'"/>
            </div>
            <div class="div_game_thumb">
                <img src="img/games/GunsOfTheNation.png" onMouseOver="this.src='img/games/GunsOfTheNation_hover.png'" onMouseOut="this.src='img/games/GunsOfTheNation.png'"/>
            </div>
            <div class="div_game_thumb">
                <img src="img/games/LegendOfAce.png" onMouseOver="this.src='img/games/LegendOfAce_hover.png'" onMouseOut="this.src='img/games/LegendOfAce.png'"/>
            </div>
        </div>
    </div>
</div>
</body>
</html>

CSS 代码:

@charset "utf-8";
/* Einfache fließende Medien
   Hinweis: Für fließende Medien müssen Sie die Attribute 'height' und 'width' des Medium aus dem HTML-Code entfernen
   http://www.alistapart.com/articles/fluid-images/ 
*/
html{
    margin: 0;
    padding: 0;
    border: 0;
}
body {
    background-color: #0c0d0f;
    color: #3982aa;
}
p {
    margin: 0;
    padding: 10px;
}
img, object, embed, video {
    width: 100%;
}
/* IE 6 unterstützt keine maximale Breite, verwenden Sie daher eine Standardbreite von 100% */
.ie6 img {
    width: 100%;
}
.div_game_thumb {
    width:320px;
    height:350px;
    display:inline-block;
    border:1px solid #fff;
}
/*
    Dreamweaver-Eigenschaften für fließende Raster
    ----------------------------------
    dw-num-cols-mobile:     6;
    dw-num-cols-tablet:     8;
    dw-num-cols-desktop:    14;
    dw-gutter-percentage:   15;

    Idee durch den Artikel "Responsive Web Design" von Ethan Marcotte 
    http://www.alistapart.com/articles/responsive-web-design

    und "Golden Grid System" von Joni Korpi
    http://goldengridsystem.com/
*/

/* Layout für Mobilgeräte: 480 px oder weniger. */

.gridContainer {
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}
#div_header {
    clear: both;
    float: left;
    margin: 0;
    width: 100%;
    display: block;
}
#div_header_img {
    width: 450px;
    height: 150px;
    background-color: #999;
    background-position: top center;
    background-repeat: no-repeat;
    background-image: url(img/header_m.png);
}
#div_menu {
    width: 450px;
    height: 50px;
    background-color: #111;
}
#div_main {
    clear: both;
    float: left;
    margin: 0;
    width: 100%;
    display: block;
    min-height: 300px;
}
#div_page {
    width: 450px;
    min-height: 300px;
    background-position: top center;
    background-repeat: repeat-x;
    background-image: url(img/page_border_top.png);
    background-color: #000;
}

/* Layout für Tablet-PCs: 481 bis 768 px. Erbt Stile vom: Layout für Mobilgeräte. */

@media only screen and (min-width: 481px) {
    body {
        background-position: top center;
        background-repeat: repeat;
        background-image: url(img/bg.png);
    }
    #div_header {
        clear: both;
        float: left;
        width: 100%;
        display: block;
        display: block;
        background-position: top center;
        background-repeat: repeat-y;
        background-image: url(img/page_bg_t.png);
    }
    #div_header_img {
        width: 650px;
        height: 150px;
        display: block;
        background-image: url(img/header_t.png);
    }
    #div_menu {
        width: 650px;
        background-position: top center;
        background-repeat: no-repeat;
        background-image: url(img/menu_bg_t.png);
    }
    #div_main {
        clear: both;
        float: left;
        margin: 0;
        width: 100%;
        display: block;
        background-position: top center;
        background-repeat: repeat-y;
        background-image: url(img/page_bg_t.png);
    }
    #div_page {
        width: 650px;
    }
}

/* Desktoplayout: 769 bis maximal 1232 px.  Erbt Stile von: den Layouts für Mobilgeräte und Tablet-PCs. */

@media only screen and (min-width: 769px) {
    #div_header {
        clear: both;
        float: left;
        width: 100%;
        display: block;
        background-image: url(img/page_bg.png);
    }
    #div_header_img {
        width: 1000px;
        height: 200px;
        background-image: url(img/header.png);
    }
    #div_menu {
        width: 1000px;
        background-position: top center;
        background-repeat: no-repeat;
        background-image: url(img/menu_bg.png);
    }
    #div_main {
        clear: both;
        float: left;
        margin: 0;
        width: 100%;
        display: block;
        background-image: url(img/page_bg.png);
    }
    #div_page {
        width: 1000px;
    }
}
4

2 回答 2

1

使用vertical-align: top;.div_game_thumb

内联元素服从垂直对齐。

此外,如果您想要跨浏览器内联块 (IE7+),您需要像这样定义它:

display: inline-block;
*zoom: 1;
*display: inline;

*注意:顺序很重要。

于 2012-10-03T22:18:47.520 回答
0

vertical-align: top节省一天!穿上它.div_game_thumb

您也可以通过添加来恢复执行此操作后消失的一点点边距margin: 2px 0;

于 2012-10-03T22:18:36.230 回答