使CSS菜单项和标题展开以更正宽度

时间:2014-06-28 06:57:33

标签: javascript jquery html css formatting

我一直试图将菜单项扩展为全宽。由于某种原因,他们缩进.. 此外,如果我使用更多字符扩展菜单名称,则会影响格式化。我试图让它自动展开,但如果我删除宽度'财产变得搞砸了。

谢谢!

小提琴代码:http://jsfiddle.net/n877s/5/

<div class="wrapper-demo">
<div id="dd" class="wrapper-dropdown-3" tabindex="1">
    <span>username</span>
        <ul class="dropdown">
        <li><a href="#">Link #1</a></li>
        <li><a href="#">Link #2</a></li>
        <li><a href="#">Link #3</a></li>
        </ul>
</div>

CSS

  .wrapper-dropdown-3 .dropdown {
  /* Size & position */
    position: absolute;
    top: 140%;
    left: 0;
    right: 0;

    /* Styles */
    background: black;
    border-radius: inherit;
    border: 1px solid rgba(0,0,0,0.17);
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
    font-weight: normal;
    -webkit-transition: all 0.5s ease-in;
    -moz-transition: all 0.5s ease-in;
    -ms-transition: all 0.5s ease-in;
    -o-transition: all 0.5s ease-in;
    transition: all 0.5s ease-in;
    list-style: none;

    /* Hiding */
    opacity: 0;
    pointer-events: none;
}

.wrapper-dropdown-3 .dropdown:after {
    content: "";
    width: 0;
    height: 0;
    position: absolute;
    bottom: 100%;
    right: 15px;
    border-width: 0 6px 6px 6px;
    border-style: solid;
    border-color: #fff transparent;    
}

.wrapper-dropdown-3 .dropdown:before {
    content: "";
    width: 0;
    height: 0;
    position: absolute;
    bottom: 100%;
    right: 13px;
    border-width: 0 8px 8px 8px;
    border-style: solid;
    border-color: rgba(0,0,0,0.1) transparent;    
}

.wrapper-dropdown-3 .dropdown li a {
    display: block;
    padding: 10px;
    text-decoration: none;
    color: #8aa8bd;
    border-bottom: 1px solid #e6e8ea;
    box-shadow: inset 0 1px 0 rgba(255,255,255,1);
    -webkit-transition: all 0.3s ease-out;
    -moz-transition: all 0.3s ease-out;
    -ms-transition: all 0.3s ease-out;
    -o-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}


.wrapper-dropdown-3 .dropdown li i {
    float: right;
    color: inherit;
}

.wrapper-dropdown-3 .dropdown li:first-of-type a {
    border-radius: 7px 7px 0 0;
}

.wrapper-dropdown-3 .dropdown li:last-of-type a {
    border: none;
    border-radius: 0 0 7px 7px;
}

/* Hover state */

.wrapper-dropdown-3 .dropdown li:hover a {
    background: #f3f8f8;
}

/* Active state */

.wrapper-dropdown-3.active .dropdown {
    opacity: 1;
    pointer-events: auto;
}

/* No CSS3 support */

.no-opacity       .wrapper-dropdown-3 .dropdown,
.no-pointerevents .wrapper-dropdown-3 .dropdown {
    display: none;
    opacity: 1; /* If opacity support but no pointer-events support */
    pointer-events: auto; /* If pointer-events support but no pointer-events support */
}

.no-opacity       .wrapper-dropdown-3.active .dropdown,
.no-pointerevents .wrapper-dropdown-3.active .dropdown {
    display: block;
}

2 个答案:

答案 0 :(得分:1)

我希望这是你需要的。更改了一些内容,例如从下拉类(间距修复)左侧填充,在.wrapper-dropdown-3上将宽度更改为自动,并在carret周围添加了一些间距。

http://jsfiddle.net/n877s/8/

我在按钮中添加了虚拟文本,仅用于测试目的,并且效果很好。

答案 1 :(得分:0)

缩进是由UL默认左边填充(或任何浏览器填充)引起的,它是40px。所以,设置

 .wrapper-dropdown-3 {margin-left: 0; padding-left: 0;}

如果子菜单中的项目较长且不想设置width,则可以使用

强制执行单行项目
white-space: nowrap;