这个多余的空间从哪里来? [英] Where does this extra space come from?

查看:103
本文介绍了这个多余的空间从哪里来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如图所示(我也将代码放入其中以使其变得更简单).该网站横向滚动(不应该发生),正文为蓝色轮廓,但右侧有额外的可滚动空间.

As seen in the picture(I also put the code in to try and make it a little easier). The website is scrolled sideways (which shouldn't happen) and the body is in the blue outline but there is extra scrollable space at the right hand side.

您也可以在CSS中看到,我可以使用overflow-x: hidden;隐藏多余"空间,但这还不够好,因为如果我要在使用overflow-x: hidden;的同时在另一个元素上使用float: right;float: right;元素将不在屏幕边缘.

As you can also see in the css I can hide the "extra" space by using overflow-x: hidden; but it's not good enough because if I were to the use float: right; on another element, while using the overflow-x: hidden;, the float: right; element would be off the edge of the screen.

我的问题是,这个额外"空间是从哪里来的?

My question is where is this "extra" space coming from?

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Test Site</title>
    <meta name="viewport" content="width=device-width, initial-width=1, user-scalable=0">
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">

</head>

<body>
<!--    <div id="navanchor"></div>Anchor to change nav size on scroll-->
        <div id="container">

            <nav id="nav">
                <img id ="logo" src="http://placehold.it/160x75" alt="Max's barbers logo.">

                <ul id="menu">
                    <li><a href="#top">Home</a></li>
                    <li><a href="#prices">Prices</a></li>
                    <li><a href="#aboutus">About Us</a></li>
                    <li><a href="#contact">Contact</a></li>
                </ul><!--menu-->
            </nav>

<!--slider-->
            <!--=============-->
<!--end slider-->
<!--            <div id="top"></div>Anchor for scroll to top button-->
    </div><!--container-->

<!--Scripts
=====================================================-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<!--Custom JS
=====================================================-->
    <script src="assets/js/app.js"></script>

<!--==============-->



</body>
</html>

& CSS

/*      1 - Fonts
        2 - Site Wide Styles
            2a - Navigation
            2b - Scrollbar
            2c- Selection
        3 - Sections
        4 - Media Queries
==============================================================*/
/* 1 - fonts
==============================================================*/
@import url(http://fonts.googleapis.com/css?family=Oswald|Raleway);
/*
font-family: 'Oswald', sans-serif;

font-family: 'Raleway', sans-serif;
*/
/* 2 - site wide styles
==============================================================*/
* {
    color: #75e7ff;
    font-family: 'Oswald', sans-serif;

    -webkit-transition: all 0.43s cubic-bezier(0.35, 1.32, 0.49, 1.01);
    transition: all 0.43s cubic-bezier(0.35, 1.32, 0.49, 1.01);
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
/*    overflow-x: hidden;*/
}

body {
    background-color: #383838;
}

#container {
    width: 100%;
}

ul {
    margin: 0;
    padding: 0;
}

/* 2a - Navigation
==============================================*/
nav {
    width: 100vw;
    height: 4.75em;
    padding: 0.5em 2em;
    background-color: rgba(255, 255, 255, 0.25);
}

#menu {
    float: right;
    margin-top: 1.5em;
    margin-right: 5.25em;
}

#menu li {
    display: inline;
    margin-left: 1.5em;
}
#menu li:first-child {
    margin: 0;
}

/* 3 - Sections
==============================================================*/
/* 3a - Home
==============================================*/


/* 4 - Media Queries
==============================================================*/

推荐答案

有两个问题导致此问题.首先,

There are two issues causing this problem. First,

nav {
    width: 100vw; /* remove this -- you don't need it! */
    ...
}

第二,如另一个答案所述,

Second, as mentioned in the other answer,

#menu {
    float: right;
    margin-top: 1.5em;
    margin-right: 0; /* changed from 5.25em */
}

jsFiddle: http://jsfiddle.net/voveson/0gLvog4q/1/

jsFiddle: http://jsfiddle.net/voveson/0gLvog4q/1/

这篇关于这个多余的空间从哪里来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆