html - 测试响应能力时导航栏显示不正确

标签 html css responsive-design

所以我有这个带有导航栏的页面,在导航栏上,左边有一个 img 标志,右边有 3 个链接。当我在 Chrome 上测试设备的响应能力时,导航栏会调整大小并向左移动,在右侧留下一个空白区域。这是图片Nav bar not displaying fully

这是我所有的代码:

    @font-face {
        font-family: coyote;
        src: url(font/coyote.ttf);
    }
    html {
        width: 100%;
        height: 100%;
    }
    * {
        margin: 0;
        padding: 0;
    }
    body {
        overflow: hidden;
        margin: 0;
        padding: 0;
    }
    nav {
        background: #efefef;
        overflow: hidden;
        box-shadow: -2px -7px 47px 9px rgba(0, 0, 0, 0.35);
        -moz-box-shadow: -2px -7px 47px 9px rgba(0, 0, 0, 0.35);
        -webkit-box-shadow: -2px -7px 47px 9px rgba(0, 0, 0, 0.35);
        z-index: 999;
        margin: 0;
        padding: 0;
    }
    .logo-section {
        float: left;
        padding: 25px;
        font-family: serif;
    }
    .logo-left {
        width: 12%;
        float: left;
        overflow: none;
        display: block;
        margin: auto;
        transform: translateY(20%);
    }
    .hb-button {
        float: right;
        background-color: rgba(0, 0, 255, 0);
        color: black;
        border: none;
        font-size: 18px;
        padding: 9px 10px;
        border-radius: 3px;
        cursor: pointer;
        display: none;
        outline: none;
    }
    nav a {
        text-decoration: none;
        color: #282828;
        font-size: 16px;
    }
    nav ul {
        overflow: hidden;
        color: #fff;
        margin: 0;
        height: 68px;
        text-align: center;
        transition: max-height 0.5s;
        -webkit-transition: max-height 0.5s;
        -moz-transition: max-height 0.5s;
        -ms-transition: max-height 0.5s;
        -o-transition: max-height 0.5s;
    }
    nav ul li {
        float: right;
        display: inline-block;
        font-family: coyote;
    }
    li > a {
        color: #000;
        text-decoration: none;
        transition-timing-function: ease-in-out;
    }
    li > a:hover {
        color: #CF2034;
        transition: color .7s cubic-bezier(0.11, 0.7, 0, 1);
        -o-transition: color .7s cubic-bezier(0.11, 0.7, 0, 1);
        -moz-transition: color .7s cubic-bezier(0.11, 0.7, 0, 1);
        -webkit-transition: color .7s cubic-bezier(0.11, 0.7, 0, 1);
        transition-timing-function: ease-in-out;
    }
    li > a:after {
        position: absolute;
        bottom: 0;
        left: 0;
        display: block;
        width: 100%;
        height: 2px;
        background-color: #CF2034;
        content: "";
        transform: scale(0);
        -o-transition: transform 1s cubic-bezier(0.11, 0.7, 0, 1);
        -moz-transition: transform 1s cubic-bezier(0.11, 0.7, 0, 1);
        -webkit-transition: transform 1s cubic-bezier(0.11, 0.7, 0, 1);
        transition: transform 1s cubic-bezier(0.11, 0.7, 0, 1);
        transition-timing-function: ease-in-out;
    }
    li > a:hover:after {
        transform: scale(1);
    }
    .image-cont {
        position: absolute;
        min-width: 45%;
        min-height: 45%;
        top: 55%;
        left: 50%;
        overflow: visible;
    }
    .image {
        animation: load_up 2s forwards;
        -webkit-animation: load_up 2s forwards;
        -moz-animation: load_up 2s forwards;
        -o-animation: load_up 2s forwards;
        margin-top: -50%;
        margin-left: -50%;
        position: relative;
    }
    .image-cont2 {
        position: absolute;
        top: 35%;
        left: 50%;
        overflow: visible;
    }
    .image2 {
        display: none;
        animation: load_up 2s forwards;
        -webkit-animation: load_up 2s forwards;
        -moz-animation: load_up 2s forwards;
        -o-animation: load_up 2s forwards;
    }
    @media screen and (max-device-width: 1603px) and (min-device-width: 1081px) {
        * {
            margin: 0;
            padding: 0;
        }
        header {
            padding: 0;
            margin: 0;
        }
        nav {
            margin: 0;
            padding: 0;
            width: 100%;
        }
        nav ul {
            margin: 0;
            padding: 0;
            z-index: 99999;
        }
        nav ul li {
            margin 0;
        }
    }
    @media screen and (max-device-width: 1080px) {
        .logo-section {
            float: none;
        }
        nav ul {
            background: #ffffff;
            max-height: 0px;
            height: 0;
        }
        nav ul.show {
            max-width: 100%;
            max-height: 100%;
            z-index: 9999;
            height: 100%;
            width: 100%;
        }
        nav ul li {
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            padding: 15px;
            padding-left: 25%;
            text-align: center;
        }
        nav a {
            display: block;
        }
        .hb-button {
            display: inline;
        }
        .image {
            display: none;
        }
        .image2 {
            display: block;
            margin-top: -35%;
            margin-left: -50%;
        }
        .logo-left {
            transform: translateY(-65%);
            padding-left: 15px;
            width: 10%;
        }
    }
    @keyframes load_up {
        0% {
            opacity: 0;
            transform: translateY(11%);
        }
        100% {
            opacity: 1;
            transform: translateY(0px);
        }
    }
    @-webkit-keyframes load_up {
        0% {
            opacity: 0;
            transform: translateY(11%);
        }
        100% {
            opacity: 1;
            transform: translateY(0px);
        }
    }
    @-moz-keyframes load_up {
        0% {
            opacity: 0;
            transform: translateY(11%);
        }
        100% {
            opacity: 1;
            transform: translateY(0px);
        }
    }
    @-o-keyframes load_up {
        0% {
            opacity: 0;
            transform: translateY(11%);
        }
        100% {
            opacity: 1;
            transform: translateY(0px);
        }
    }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/responsive_navbar.js"></script>
<link rel="stylesheet" href="main.css">
<header>
    <nav>
        <div class="logo-section">
            <button class="hb-button"><i class="fa fa-bars" aria-hidden="true"></i>
            </button>
        </div>

        <div style="min-width: 1920px; margin: 0 auto;">
            <a href="index.html"><img src="img/thermocase.png" class="logo-left">
            </a>
        </div>

        <ul>
            <li><a href="contact.html"> &#9679; Contact Us</a>
            </li>
            <li><a href="team.html"> &#9679; The Team</a>
            </li>
            <li><a href="product.html"> &#9679; Our Product</a>
            </li>
        </ul>
    </nav>
</header>


<div class="image-cont">
    <img src="img/iphone.png" class="image" />
</div>
<div class="image-cont2">
    <img src="img/iphone2.png" class="image2" />
</div>

感谢您的关注。仅供引用,我是新手。

最佳答案

您可以从两件事开始。

你需要有你的开口<body>关闭后立即标记 </head>标记,因此您可能要考虑使用另一个 div 来包装页面上的主要内容

<html>
 <head> ... </head>
 <body>
  <header> ... </header>
   <div class="main-content"> ... </div>
 </body>
</html>

其次,在您的 HTML 的第 19 行

<div style="min-width: 1920px; margin: 0 auto;">  

一旦视口(viewport)小于 1920 像素,像这样对元素的宽度进行硬编码会给您带来困难。您可能想要删除此内联 CSS,并将其替换为一个类。然后您可以使用 CSS media queries 轻松操纵 div 的宽度。 ,例如

HTML

<div class="logo-wrap"> ... </div>   

CSS

.logo-wrap{
 ...
}  

@media (min-width: 1920px) {  
 min-width: 1920px; 
 margin: 0 auto;
}

编辑

尝试将视口(viewport)元标记更改为

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

祝你好运!

关于html - 测试响应能力时导航栏显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47495493/

相关文章:

css - 将 div B 置于 div A 之上

html - 制作宽表,在移动设备上折叠成行

JavaScript/计时

html - 页眉始终在顶部,页脚始终在底部

javascript - 从 json 对象收集数据并创建层次结构

javascript - Angular 指令使选定的子菜单及其父菜单处于事件状态并关闭所有其他打开的元素

jquery - 如何阻止页面刷新?

html - 多水平 div 网站上的页脚

html - 如何在 prestashop 上对齐复选框和标签

css - 响应式媒体查询 - 我在哪里放置什么代码?