尽管代码相同,但在不同位置切换面板

toggle panels in different positions despite the same code

我的问题是由于 jQuery toggle() 方法,我有两个面板显示和隐藏。在 jQuery 方面,我完全是个菜鸟,我使用教程制作了一个面板,然后使用相同的代码制作了第二个面板。最后,新的看起来比第一个低很多,我不知道如何修复它。此外,新面板几乎覆盖了网站的整个部分,除了在面板顶部清晰可见的菜单链接之外,它不应该像那样。我该如何解决?

$(document).ready(function(){
    $('#cards div:not(:first)').hide();
    
    $('#list li').click(function(e){
        $('#cards div').hide();
        $('#list .current').removeClass("current").children().removeClass("open");
        $(this).addClass('current');
        $(this).children().addClass('open');
        
        var clicked = $(this).find('a:first').attr('href');
        $('#cards ' + clicked).fadeIn('fast');
        e.preventDefault();
    }).eq(0).addClass('current');
    
    $('.form_container').hide();
    $('button.trigger').click(function(){
       $(this).toggleClass("active").next().slideToggle("slow");
       return false;
    });
});
body
{
    background-image: url("img/wood7.jpg");
}

#container
{
    //background-color: darkorange;
    width: 70%;
    height: auto;
    margin-left: auto;
    margin-right: auto;
}

#head
{
    //background-color: lightblue;
    width: 98%;
    height: 100px;
    margin: 0 auto;
}

#reg_welcome
{
    background-color: rgba(0,0,0,0.3);
    width: 24%;
    height: 100%;
    float: left;
    margin-right: 1%;
}

#logo
{
    background-color: rgba(0,0,0,0.3);
    width: 50%;
    height: 100%;
    float: left;
}

#login_out
{
    background-color: rgba(0,0,0,0.3);
    float: left;
    width: 24%;
    height: 100%;
    margin-left: 1%;
}

#content
{
    //background-image: url(img/sheet.png);
    //background-color: green;
    width: 95%;
    height: 700px;
    margin-top: 10px;
    margin-bottom: 10px;
    margin-right: auto;
    margin-left: auto;
}

/* CARDS */

#marks
{
    //background-color: lawngreen;
    width: 100%;
    height: 45px;
}

#list
{
    list-style: none;
    margin: 0px;
    padding: 0px;
    text-align: center;
}

#list li a
{
    font-size: 24px;
    float: left;
    width: 200px;
    line-height: 40px;
    text-decoration: none;
    text-align: center;
    background-color: palegoldenrod;
    opacity: 0.7;
    display: block;
    margin-top: 5px;
    margin-left: 5px;
    margin-right: 5px;
}

#list li a:hover
{
    opacity: 1;
}

#cards
{
    width: 100%;
    height: 90%;
}

#news
{
    background-color: firebrick;
    width: 100%;
    height: 100%;
}

#fics
{
    background-color: indigo;
    width: 100%;
    height: 100%;
}

#other_stories
{
    background-color: palegoldenrod;
    width: 100%;
    height: 100%;
}

.open
{
    color: red;
}

/* END OF CARDS */

.categories
{
    
}

#footer
{
    background: rgba(0,0,0,0.4);
    width: 98%;
    height: 75px;
    margin: 0 auto;
    text-align: center;
}

#author
{
    font-size: 18px;
    line-height: 132px;
    color: goldenrod;
    font-style: italic;
}

button
{
    width: 127px;
    height: 38px;
    font-weight: bold;
    border-radius: 7px;
    margin: 5px;
    box-shadow: 3px 3px 10px #000000, inset -3px -3px 10px #bfb6b6;
}

#log_in
{
    float: right;
}

.form_container
{
    margin-top: 45px;
    margin-left: auto;
    margin-right: auto;
    padding: 7px;
    background-color: #ABE2F7;
    width: 90%;
}

.trigger.active
{
    background-position: right bottom;
}

input
{
    width: 88%;
    height: 18px;
    background: #EFEFEF;
    border: 1px solid #DEDEDE;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    padding: 10px;
    margin-top: 3px;
    font-size: 0.9em;
    color: #3A3A3A;
}

.submit
{
    width: 127px;
    height: 38px;
    font-weight: bold;
    border:none;
    margin-top: 20px;
    cursor: pointer;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body>
        <div id="container">
            <div id="head">
                <div id="reg_welcome">
                    <button type="button" class="trigger" id="register" onclick="showPanel">Sign up</button>
                    <div class="form_container">
                        <form action="" method="post" id="register_form">
                            E-mail: 
                            <input type="text" name="mail" /> <br />
                            Login:
                            <input type="text" name="login" /> <br />
                            Password:
                            <input type="password" name="pass" /> <br />
                            Re-type password:
                            <input type="password" name="repass" /> <br />
                            <input type="submit" class="submit" name="submit_log" value="Sign up" />
                        </form> 
                    </div>
                </div>
                <div id="logo">
                    
                </div>
                <div id="login_out">
                    <button type="button" class="trigger" id="log_in" onclick="showPanel">Login</button>
                    <div class="form_container">
                        <form action="" method="post" id="login_form">
                            E-mail: 
                            <input type="text" name="mail_log" /> <br />
                            Password:
                            <input type="password" name="pass_log" /> <br />
                            <input type="submit" class="submit" name="submit_log" value="Login" />
                        </form> 
                    </div>
                </div>
            </div>

            
            <div id="content">
                <div id="marks">
                    <ul id="list">
                        <li id="card_news"><a href="#news">News</a></li>
                        <li id="card_fics"><a href="#fics">Fanfiction</a></li>
                        <li id="card_other"><a href="#other_stories">Other stories</a></li>
                    </ul>
                </div>
                <div id="cards">
                    <div id="news">
                        
                    </div>
                    <div id="fics">
                        <div class="categories">
                            
                        </div>
                    </div>
                    <div id="other_stories">
                        <div class="categories">
                            
                        </div>
                    </div>
                </div>
            </div>
            
            <div id="footer">
                <span id="author">Author: </span>
            </div>
        </div>
    </body>

问题在这里:

#log_in {
    float: right;
}

因为该元素浮动在文档流之外,所以它不会将其他元素向下推。删除它,然后调整 .form-container 的上边距以更好地适应:

.form_container {
    margin-top: 5px;
}

Demo