我试图让div的宽度根据其内容水平扩展
内容是浮动div,我希望它们显示为一行
我使用white-space: nowrap;
,但它不适用于IE和FF(它在谷歌浏览器上工作得非常好)
这是我的HTML代码:
<div class="floating_menu_container">
<div class="floating_menu">
<div class="floating_menu_item account">
<div class="sub_floating_menu">
<div class="sub_floating_menu_item"></div>
<div class="sub_floating_menu_item"></div>
</div>
</div>
</div>
</div>
这是CSS代码:
.floating_menu_container{
position: absolute;
top: 25px;
left: 5px;
height: 50px;
z-index: 5;
}
.floating_menu_container .floating_menu{
height: 0px;
width: 40px;
background: #4D75A6;
z-index: -1;
position: absolute;
top: 35px;
left: 7px;
}
.floating_menu_container .floating_menu .floating_menu_item{
width: 30px;
height: 30px;
background: #94acc9;
border: 1px solid #6991c2;
margin: 7px 0px 4px 4px;
cursor: pointer;
position: relative;
}
.floating_menu_container .floating_menu .floating_menu_item .sub_floating_menu{
height: 30px;
position: absolute;
top: 0px;
background: #4D75A6;
left: 42px;
border: 1px solid #003980;
z-index: 10;
cursor: default;
white-space: nowrap;
}
.floating_menu_container .floating_menu .floating_menu_item .sub_floating_menu .sub_floating_menu_item{
width: 20px;
height: 20px;
background: #94acc9;
margin: 5px;
float: left;
cursor: pointer;
}
以下是jsfiddle上的示例
我想根据内容
答案 0 :(得分:1)
从width: 20px;
移除.sub_floating_menu_item
,从height: 30px;
移除.sub_floating_menu
,将float: left;
替换为display: inline-block;
应该可以解决问题,小小的演示: little link