【问题标题】:How to create menu fixed to the left corner?如何创建固定在左上角的菜单?
【发布时间】:2015-08-01 00:52:58
【问题描述】:

我正在寻找如何创建像这样的菜单 http://www.panic.lv/en/ 。菜单必须双固定在左角,所以菜单可以保持滚动。当我使用本网站的 CSS 时

#nav-corner {
    width: 100%;
    height: 5em;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 800;
    overflow: hidden;
    -o-transform: skewY(-10deg);
    transform: skewY(-10deg);
}

我在我的网站上得到了这个 http://www.awesomescreenshot.com/image/443096/8c36574b9c0461dbd40f92ecb4257485

菜单不在左上角,当我缩小宽度时,他正在移动我的角落,但没有宽度:100% 我失去了角落的平静。我只能使用 top:-170 来解决这个问题,并添加高度,例如 220px;但这是一个糟糕的解决方案,因为响应速度更快,在较小的分辨率上我失去了我的图标。

有人可以帮帮我吗?

谢谢!

【问题讨论】:

    标签: html css


    【解决方案1】:

    你可以用这个

    body{
      background-color: #000000;
    }
    #wrapper {
        width: 100%;
        text-align: left;
        height: auto;
        min-height: 100%;
        position: relative;
    }
    * {
        box-sizing: border-box;
    }
    .menu-space {
        position: fixed;
        height: 203px;
        top: 0px;
        left: 0px;
        z-index: 800;
        overflow: hidden;
        transform: rotate(-10deg) translate(-50px, -177px);
        padding: 43px;
        width: calc(100% + 100px);
        background: #FFF none repeat scroll 0% 0%;
    }
    .menu-icon {
        position: fixed;
        height: 5em;
        top: 1.25em;
        left: 1.25em;
        z-index: 800;
        overflow: hidden;
        -o-transform: skewY(-10deg);
        transform: skewY(-10deg);
    }
    <div id="wrapper">
    	<div class="menu-space"></div>
    	<span class="menu-icon"><img src="http://motiongiraffx.com/wp-content/themes/motiongiraffx/images/menu-icon.png" id="nav-icon" onclick="changeImage()" alt="Menu icon"></span>
    </div>
    
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

    使用此代码,您可以删除 top: -170px 我使用 transform: rotate(-10deg) translate(-50px, -177px); 而不是 transform: skewY(-10deg); 以及 html 和 css 中的其他小更改

    可以看这里http://liveweave.com/WQZWpX


    可以解决移动问题,您只需将position: fixed; 和width: calc(100% + 100px); 添加到.responsive-menu 类

    .responsive-menu {
        display: none;
        position: fixed;
        z-index: 900;
        width: calc(100% + 100px);
    }
    

    为了解决小问题跟我来

    。在media-query.css 中将@media only screen and (max-width: 640px) { 更改为@media only screen and (max-width: 630px) {

    。将此css添加到media-query.css文件

    @media (min-width: 550px) and (max-width: 639px) {
      .resp-menu-space {
        height: 66px;
      }
    }
    

    测试一下

    【讨论】:

    • 我试过了,我的图标在正确的位置,但#nav-corner 仍然在我在屏幕截图中显示的位置。我不知道为什么这个 div 不想上 i 角落。 :(
    • 为什么是对的?我想要我的菜单在左上角?问题在于#nav-corner div,这个css不会到达顶部。请再次查看我的屏幕截图,看看主要问题是什么。
    • 你所做的一切也为我工作。我将图标放在我想要的位置,没问题,问题在于#nav-corner div 应该始终位于左上角并且 skewY(-10deg);
    • 能否请您添加更多您的 html 和 css 代码我无法理解您想要什么
    • 谢谢,但与此同时,我找到了另一种解决方案。我找到了属性 transform-origin: 0 0;它也有效。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 2019-09-21
    • 2015-02-04
    • 1970-01-01
    相关资源
    最近更新 更多