-1

我记得我以前遇到过这个问题,但我不能强调它足以记住解决方法。我有这个下拉菜单,我为了方便而摆弄了。问题是当您将鼠标悬停在点上时,可以查看子元素是如何被包装的,而不是显示在一行上。我怎样才能让他们看起来正常?

http://jsfiddle.net/N45P7/

HTML

<div class='addedForDisplayPurposes'>
    <div class="optionsList"> <span>•&lt;/span>

        <div class="optionsHolder">
            <div data-id="asdasd" class="socInt">Add Friend</div> <a href="#">Send Message</a>

        </div>
    </div>
</div>

CSS

.addedForDisplayPurposes {
    width:300px;
}
.optionsList {
    display:inline-block;
    position:relative;
    cursor:pointer;
    float:right;
}
.optionsList > span {
    font-size:20px;
    color:black;
}
.optionsList:hover > span {
    color:white;
}
.optionsList:hover .optionsHolder {
    display:inline-block;
}
.optionsHolder {
    position:absolute;
    display:none;
    top:0;
    right:0;
    background:white;
    border:solid black 1px;
    padding:5px 0 5px 0;
    z-index:3;
}
.optionsHolder > * {
    padding:5px 10px 5px 10px;
    font-weight:bold;
}
.optionsHolder > *:hover {
    background:black;
    color:white;
}
4

2 回答 2

1

进行这些更改,您的问题将得到解决。

.optionsHolder {
    position: absolute;
    display: none;
    top: 15px;
    right: 0;
    background: white;
    border: solid black 1px;
    padding: 5px 0 5px 0;
    z-index: 3;
    width: 140px;
}

编辑

如果您无法对 进行任何更改width,请添加 awhite-space:nowrap;以使文本换行。

例如,

.optionsHolder {
    position: absolute;
    display: none;
    top: 15px;
    right: 0;
    background: white;
    border: solid black 1px;
    padding: 5px 0 5px 0;
    z-index: 3;
    white-space:nowrap;
}

希望这对现在有所帮助。

于 2013-08-26T11:21:06.620 回答
0

使用 CSS 表格显示类型

另一种方法是使用 display 属性:

.optionsList:hover .optionsHolder {
    display: table;
}
.optionsHolder {
    position:absolute;
    display:none;
    top:0;
    right:0;
    background:white;
    border:solid black 1px;
    padding:5px 0 5px 0;
    z-index:3;
}
.optionsHolder > * {
    padding:5px 10px 5px 10px;
    font-weight:bold;
    display: table-cell;
}

对于.optionsHolder, setdisplay: table和对于子元素, set display: table-cell

这将允许子元素显示在父元素中的单行上,并具有缩小到适合的宽度。

演示小提琴:http: //jsfiddle.net/audetwebdesign/DmbMV/

于 2013-08-26T11:54:33.560 回答