0

我有 2 个 div,我希望一个在屏幕上居中,另一个在其父级 #MyContent 的左侧(居中的那个)。但是,似乎添加了一个“Float:left;” 到 #Latest 会导致 DOM 错误,#MyContent 不再保留 #Latest 并且它会缩小而将 #Latest 排除在外,就像 #Latest 是“position:absolute;”一样 当它的“相对”时。

我有这些:

HTML:

<center>
    <div id="MyContent">
        <div id="Latest">
            <div class="Last"></div>
        </div>
    </div>
</center>

CSS:

#MyContent {
    position: relative;
    font-family: FontStencil;
    font-size: 12px;
    padding: 20px 20px 160px 20px;
    color: black;
    background: rgba(240, 240, 240, 0.2);
    border-radius: 18px;
    border: 1px solid #CCCCCC;
    top: 250;
    width: 950px;
    box-shadow: 0px 5px 15px -2px black;
}

#Latest {
    position: relative;
    font-family: FontStencil;
    float: left; /* When I remove THIS, everything works Fine BUT its all centered */
    text-align: left;
    font-size: 18px;
    padding: 20px 20px 30px 20px;
    color: #000033;
    background: white;
    border-radius: 18px;
    border: 1px solid #CCCCCC;
    left: 20px;
    top: 30px;
    width: 570px;
    box-shadow: 0px 1px 17px -5px black;
}

.Last {
    position: relative;
    font-family: SuperG;
    text-align: left;
    right: -18px;
    font-size: 12px;
    padding: 15px;
    color: #000033;
    background: white;
    border-radius: 18px;
    border: 1px solid #CCCCCC;
    top: 25px;
    width: 500px;
    height: 415px;
    box-shadow: 0px 1px 17px -5px black;
}

一切都是位置:相对;但是当我添加一个 float:left; 时,它的行为就像 #Latest 不是 暂停。

4

1 回答 1

1

CSS

#MyContent{
font-family:FontStencil;
font-size:12px;
padding:20px 20px 160px 20px;
color:black;
background:rgba(240,240,240, 0.2);
border-radius:18px;
border:1px solid #CCCCCC;
top:250;
width:950px;
box-shadow: 0px 5px 15px -2px black;
margin: 0 auto;
    display: inline-block;
}

#Latest{
position:relative;
font-family:FontStencil;
float: left; /* When I remove THIS, everything works Fine BUT its all centered */
text-align:left;
font-size:18px;
padding:20px 20px 30px 20px;
color:#000033;
background:white;
border-radius:18px;
border:1px solid #CCCCCC;
left:20px;
top:30px;
width:570px;
box-shadow: 0px 1px 17px -5px black;
}

.Last{
position:relative;
font-family:SuperG;
text-align:left;
right:-18px;
font-size:12px;
padding:15px;
color:#000033;
background:white;
border-radius:18px;
border:1px solid #CCCCCC;
top:25px;
width:500px;
height:415px;
box-shadow: 0px 1px 17px -5px black;
}

试试上面的 CSS。演示

于 2013-08-30T07:44:40.523 回答