0

所以,我在同一行中有 2 个 DIV 元素。但是当我把内容放在第二个上时,第一个就下降了。这是代码和结果。

jsfiddle

<div style="margin-top: 5px;"></div>
<div style="display: inline-block; width:250px; height:180px; background-color:#fff; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);">
    <center>
        <div style="font-weight: bold; text-align: center; width: 250px; height: 50px; font-family: 'Droid Sans', sans-serif; color:#000; font-size:12px; border:0; height:100%; line-height: 30px;">Top 5 Números Ganhadores 1º -</div>
    </center>
</div>
<div style="display: inline-block; width:250px; height:180px; background-color:#fff; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);">
    <center>
        <div style="font-weight: bold; text-align: center; width: 250px; height: 50px; font-family: 'Droid Sans', sans-serif; color:#000; font-size:12px; border:0; height:100%; line-height: 30px;">Top 5 Números Escolhidos
            <p>1º -</div>
    </center>
</div>
4

2 回答 2

2

这是因为你的语法有错误

<div style="margin-top: 5px;"> </div>
<div style="display: inline-block; width:250px; height:180px; background-color:#fff; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);">
<center>
    <div style="font-weight: bold; text-align: center; width: 250px; height: 50px; font-family: 'Droid Sans', sans-serif; color:#000; font-size:12px; border:0; height:100%; line-height: 30px;">
        Top 5 Números Ganhadores
        1º -
    </div>
</center>
</div>
<div style="display: inline-block; width:250px; height:180px; background-color:#fff; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);">
<center>
    <div style="font-weight: bold; text-align: center; width: 250px; height: 50px; font-family: 'Droid Sans', sans-serif; color:#000; font-size:12px; border:0; height:100%; line-height: 30px;">
        Top 5 Números Escolhidos<p>
        1º - 
    </div>
</center>
</div>

您有一个在“Top 5 Números Escolhidos”之后从未关闭过的开始 P 标签

Top 5 Números Escolhidos<p>
        1º - 

删除它,你会很高兴的!

http://jsfiddle.net/S636H/

编辑:

想要在 div 中添加的不仅仅是文本?只需将两个 div 浮动到左侧,并确保关闭 p 标签。

<div style="margin-top: 5px;"> </div>
<div style="display: inline-block; width:250px; height:180px; background-color:#fff; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);">
<center>
    <div style="font-weight: bold; text-align: center; width: 250px; height: 50px; font-family: 'Droid Sans', sans-serif; color:#000; font-size:12px; border:0; height:100%; line-height: 30px; float:left;">
        Top 5 Números Ganhadores
        1º -
    </div>
</center>
</div>
<div style="display: inline-block; width:250px; height:180px; background-color:#fff; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);">
<center>
    <div style="font-weight: bold; text-align: center; width: 250px; height: 50px; font-family: 'Droid Sans', sans-serif; color:#000; font-size:12px; border:0; height:100%; line-height: 30px; float:left;">
        Top 5 Números Escolhidos<p></p>
        1º - 
    </div>
</center>
</div>

http://jsfiddle.net/48wAA/

或者,如果您不想浮动 div,请确保 p 标签是内联的:http: //jsfiddle.net/CkGJf/

于 2013-03-13T17:41:29.283 回答
0

您尝试做的事情的本质如下:

<div class="parentPanel">
    <div class="boxyPanel">The Left Div</div>
    <div class="boxyPanel">The Right Div</div>
</div>

做样式的 CSS 是:

.parentPanel {
background-color: #f0f0f0;
overflow: auto;
text-align: center;    
}
.boxyPanel {
display: inline-block;
width: 250px;
height: 150px;
border: 1px solid blue;
}

见小提琴:http: //jsfiddle.net/audetwebdesign/GVgun/

于 2013-03-13T17:42:00.430 回答