jQuery show函数扭曲页面样式

时间:2015-02-25 08:20:16

标签: javascript jquery html css show

所以如果选择了合适的选项,我会显示一个额外的div。在Firefox中工作得很好,但在Chrome或Safari中显示额外的div时,页脚会保持原样。它不会回到底部。

以下是一个示例,尝试在Safari或Firefox中打开它。 输出窗口的高度应该很小,以确定问题是什么

Fiddle

一些代码,查看Fiddle上的示例(查看上面的链接)

    <style>
    html, body {
        height: 100%;
        margin: 0;
        overflow-x: hidden;
        padding: 0;
        position: relative;
        width: 100%;
    }
    body {
        display: -webkit-flex;
        /* Safari */
        -webkit-flex-direction: column;
        /* Safari 6.1+ */
        display: flex;
        flex-direction: column;
    }
    .content {
        background-color: #f7f7f7;
        clear: both;
        min-height: 250px;
        padding: 20px 10%;
    }
</style>
<script>
    $(document).ready(function () {
        $("#extra_div").hide();
    });


    $('.selectpicker').change(function () {

        if ($(this).val() == '3') {
            $("#extra_div").show();
        } else {
            $("#extra_div").hide();
        }


    })
</script>

<body>
    <div id="okvir_registracije" style="background-color: #f7f7f7;margin-top: 73px; -webkit-flex: 1; -ms-flex: 1; flex: 1;">
        </br>
        <div class="content" id="login_content">
            <form name="registration" class="registration" method="post" id="form_login" onsubmit="return validateForm();">
                <fieldset style="background: white">
                    <label style="margin-left: 10px">Choose one:</label>
                    <select class="selectpicker" name="tip_uporabnika" id="tip_uporabnika" for="tip_uporabnika" onchange="show_div()">
                        <option value="1" selected="selected">izberi tip uporabnika</option>
                        <option value="3">Uporabnik</option>
                    </select>
                    <div id="extra_div">
                        </br>
                        <label style="margin-left: 10px" for="ime">Test 2</label>
                        </br>
                        <label style="margin-left: 10px">Test</label>
                        <select class="selectpicker" name="tip_uporabnika" id="tip_uporabnika" for="tip_uporabnika" onchange="show_div()">
                            <option value="1" selected="selected">izberi tip uporabnika</option>
                            <option value="2">Uporabnik</option>
                            <option value="3">Lastnik</option>
                        </select>
                        </br>
                        <label style="margin-left: 10px" for="ime">Name</label>
                        <input type="text" id="firstname" name="firstname" placeholder="vaše ime...">
                        <br/>
                        <label style="margin-left: 10px" for="priimek">Surname</label>
                        <input type="text" id="lastname" name="lastname" placeholder="vaš priimek...">
                        <br/>
                        <label style="margin-left: 10px" for="username">Example</label>
                        <input type="text" id="username" name="username" placeholder="vaše uporabniško ime...">
                        <br/></br>
                        <label style="margin-left: 10px" for="ime">Name</label>
                        <input type="text" id="firstname" name="firstname" placeholder="vaše ime...">
                        <br/>
                        <label style="margin-left: 10px" for="priimek">Surname</label>
                        <input type="text" id="lastname" name="lastname" placeholder="vaš priimek...">
                        <br/>
                        <label style="margin-left: 10px" for="username">Example</label>
                        <input type="text" id="username" name="username" placeholder="vaše uporabniško ime...">
                        <br/></br>
                        <label style="margin-left: 10px" for="ime">Name</label>
                        <input type="text" id="firstname" name="firstname" placeholder="vaše ime...">
                        <br/>
                        <label style="margin-left: 10px" for="priimek">Surname</label>
                        <input type="text" id="lastname" name="lastname" placeholder="vaš priimek...">
                        <br/>
                        <label style="margin-left: 10px" for="username">Example</label>
                        <input type="text" id="username" name="username" placeholder="vaše uporabniško ime...">
                        <br/>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
    <hr>
    <div id="footer" style="padding: 15px 0;text-align: center;width: 100%;height:25px;">&copy; Company | info@company.si</div>
</body>

这是两张图片:

Safari浏览器:

Safari image

火狐:

Firefox image

3 个答案:

答案 0 :(得分:1)

这与你给身体的身高属性有关。 这使得页脚无论如何都会粘在底部。

如果您想要一个粘性页脚,请尝试其中一个示例,这应该可以解决您的问题。

http://css-tricks.com/snippets/css/sticky-footer/

http://ryanfait.com/sticky-footer/

答案 1 :(得分:1)

将高度设置为100%将产生当前浏览器窗口大小的高度。默认情况下,Div会根据内容进行调整。删除所有height: 100%约束,你应该没问题。

答案 2 :(得分:0)

删除display:flex css规则可解决此问题。不确定表单的确切最终结果应该是什么,但在删除上述规则时它不会与页脚重叠。

https://jsfiddle.net/v4po4gwc/22/