English 中文(简体)
CSS 下调对齐
原标题:CSS drop down alignment

我正在尝试创建一个下拉菜单, 当您单击它时, 它会打开一个 ul 。 关键是我要“ 查看更多” 按钮始终在它所在的位置, 而打开它下面的下拉键 。

如果你去下面的链接, 你会看到我的意思。 它的打开和我想的完全一样, 但是如果你点击“ View More” 关闭了下降点, 你会看到页眉移动到左边, 当我希望它保持原样的时候

我建这个,是为了能在许多不同的地方被使用, 所以“硬码”的大小是无法选择的。

请帮助! :)

HTML HTML

<div id="testcontainer">

        <a href="javascript:;" class="dropdown-activator" dropdownContent="#dropdown-content-340">
            <span>View More!</span>
        </a>

        <ul class="dropdown-content" id="dropdown-content-340">
            <li><a href="http://www.google.com" class="googleIcon">Google</a></li>
            <li><a href="http://www.yahoo.com" class="yahooIcon">Yahoo</a></li>
            <li><a href="http://www.bing.com" class="bingIcon">Bing</a></li>
        </ul>


    </div>

    <div id="testcontainer2">

        <a href="javascript:;" class="dropdown-activator" dropdownContent="#dropdown-content-350">
            <span>View More!</span>
        </a>

        <ul class="dropdown-content" id="dropdown-content-350">
            <li><a href="http://www.google.com" class="googleIcon">Google</a></li>
            <li><a href="http://www.yahoo.com" class="yahooIcon">THIS IS A TEST FOR WIDER SHIT</a></li>
            <li><a href="http://www.bing.com" class="bingIcon">Bing</a></li>
        </ul>

    </div>

    <div id="testcontainer3">

        <a href="javascript:;" class="dropdown-activator" dropdownContent="#dropdown-content-400">
            <span>View More!</span>
        </a>

        <ul class="dropdown-content" id="dropdown-container-400">
            <li><a href="http://www.google.com" class="googleIcon">GOOOOOOOOOOOOOOOOOOOOOGLEASDASDSASD</a></li>
            <li><a href="http://www.yahoo.com" class="yahooIcon">Yahoo</a></li>
            <li><a href="http://www.bing.com" class="bingIcon">Bing</a></li>
        </ul>

    </div>

CSS 安保部

#testcontainer {
position: absolute;
top: 20px;
left: 100px;
text-align: center;
}

#testcontainer2 {
position: absolute;
top: 20px;
left: 150px;
text-align: center;
}

#testcontainer3 {
position: absolute;
top: 200px;
left: 500px;
text-align: center;
}

.dropdown-activator-active {
background-color: #000;
color: #fff;
}

.dropdown a {
display: inline-block;
}

.dropdown-activator {
display: inline-block;
border: 1px solid black;
padding: 3px;
}


.dropdown-content {
visibility: hidden;
height: 0;
opacity: 0;
position: relative;
text-align: left;
margin: 0 auto;
border: 1px solid black;
}

.dropdown-content-active {
visibility: visible;
height: auto;
opacity: 1;
}

.dropdown-content ul li {
list-style: none;
}

J 查询

$(function(){

$(".dropdown-activator").click(function() {
    $this = $(this);
    var current = $this.attr( dropdownContent );
    if (!$(current).hasClass( dropdown-content-active )) {
        $this.addClass("dropdown-activator-active", 100);
        $(current).addClass( dropdown-content-active , 100, function() {
            $( html ).unbind( click );
            $( html ).not($this).one( click , function() {
                $(current).prev().removeClass("dropdown-activator-active", 100);
                $(current).removeClass( dropdown-content-active , 100);
            });
        });
    } else {
        $this.removeClass("dropdown-activator-active", 100);
        $(current).removeClass( dropdown-content-active , 100)
    }
});
});

您可以在www.chrisworrell.com(临时)上看到一个例子。

最佳回答

display: no; 将您的元素从文档流中删除, 这就是为什么您的父 div 调整大小。 另一方面, < code> 可见度: 隐藏; 将您元素隐藏在文档流中 。

您可以做的是不要操纵您的 lt;ul> 元素的显示属性, 设置 可视性: 隐藏; hile: 0; , 这样未扩展的链接将继续使用它所捆绑的 UL 元素的宽度 。

它有点黑,但应该完成它的工作。

为了控制可见度而不是显示 jQuery UI 的可见度, 请使用 < code>. animate( {不透明: 1}) 用于淡化 In () 和 < code>. animate ({不透明: 0}) 用于淡出 ()

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签