调整自定义下拉框的CSS宽度

时间:2014-01-03 15:42:21

标签: css css3

这是我为我工作的下拉框。 但它在左端超出了界限。实际上菜单项应该恰好位于文本框的下方。

Check Fiddle

我尝试更改所有元素的宽度但无法设置它。有人可以告诉我哪个类确切地控制了弹出下拉框时出现的菜单项的宽度吗?

的CSS:

.container {
    width:90%;
    margin:10% auto;
}
.dropdown-menu{
    width:85%;
    margin:0 auto;
}
.twitter-typeahead .tt-query, .twitter-typeahead .tt-hint {
    margin-bottom: 0;
    width: 360px; !important;
}
.twitter-typeahead .tt-hint {
    display: block;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.428571429;
    border: 1px solid transparent;
    border-radius:4px;
}
.twitter-typeahead .hint-small {
    height: 30px;
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 3px;
    line-height: 1.5;
}
.twitter-typeahead .hint-large {
    height: 45px;
    padding: 10px 16px;
    font-size: 18px;
    border-radius: 6px;
    line-height: 1.33;
}
.tt-dropdown-menu {
    min-width: 260px;
    margin-top: 2px;
    padding: 5px 0;
    background-color: #fff;
    border: 1px solid #ccc;
    border: 1px solid rgba(0, 0, 0, .2);
    *border-right-width: 2px;
    *border-bottom-width: 2px;
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
    -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
    -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
    box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
    -webkit-background-clip: padding-box;
    -moz-background-clip: padding;
    background-clip: padding-box;
}
.tt-suggestion {
    display: block;
    padding: 3px 20px;
}
.tt-suggestion.tt-is-under-cursor {
    color: #fff;
    background-color: #0081c2;
    background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
    background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
    background-image: -o-linear-gradient(top, #0088cc, #0077b3);
    background-image: linear-gradient(to bottom, #0088cc, #0077b3);
    background-repeat: repeat-x;
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0)
}
.tt-suggestion.tt-is-under-cursor a {
    color: #fff;
}

.tt-suggestion p {
    margin: 0;
}

1 个答案:

答案 0 :(得分:1)

在您的课程.dropdown-menu上添加以下内容:

.dropdown-menu{
  width:360px;
  left:auto;
  margin:0 auto;
}

Fiddle 演示

这是因为360px是输入.twitter-typeahead .tt-query, .twitter-typeahead .tt-hint的大小。

left:auto保持原始距离,无论绝对位置如何。

相关问题