在div中使用div(宽度:自动)(宽度:自动)

时间:2011-11-17 10:48:14

标签: css html

大家好,我对div width:auto的某些问题感到疑惑。

这是HTML:

<div class="greenMenu">
    <div class="btn">
        <img src="img/image.png" width="57" height="46" />
        <div class="area">
            <div class="txt">A Lorem ipsum</div>
        </div>
    </div>

    <div class="btn">
        <img src="img/image.png" width="57" height="46" />
        <div class="area">
            <div class="txt">A Lorem ipsum</div>
        </div>
    </div>
</div>

和CSS:

.greenMenu {
    position:absolute; 
    top:83px; 
    left:220px; 
    width:auto; 
    height:47px; 
    background:url(../img/prod-uova-ripMenu.png) left top repeat;
}

.greenMenu .btn {
    background:#090; 
    float:left; 
    margin-top:1px; 
    margin-left:6px; 
    *display:inline; 
    _display:inline; 
    width:auto; 
    height:43px; 
    position:relative;
}

.greenMenu .btn img {
    border:none; 
    position:absolute; 
    top:0px; 
    left:0px; 
    z-index:2;
}

.greenMenu .btn .area {
    background:#53882d; 
    width:auto; 
    height:32px; 
    position:absolute; 
    top:5px; 
    left:0px; 
    z-index:1;
}

.greenMenu .btn .area .txt {
    float:left; 
    margin:7px 13px 0 60px;
}

问题是:greenMenu无法扩展其宽度,同时div.btn宽度为0。

1 个答案:

答案 0 :(得分:0)

不要在那里使用以下代码:

 position: absolute;