【问题标题】:hamburger menu fixed on bottom right, bootstrap汉堡菜单固定在右下角,引导程序
【发布时间】:2017-08-04 19:56:15
【问题描述】:

我一直在寻找引导程序中移动菜单中的幻灯片,我能得到的最接近的是这个https://codepen.io/erikterwan/pen/EVzeRP , 但我不能让它从右到左打开并放入汉堡包右下角,有什么想法吗?

【问题讨论】:

  • 这不是 PHP 相关的问题。
  • 你试过什么?你能简单地用right替换left css定位吗?
  • @zgood,正在使用相对位置,我可以放置汉堡包但不能放置菜单,它会在移动设备上添加 x 轴滚动,这根本不好。我使用变换和变换移动菜单位置-起源。也许你知道另一种滑入菜单的方法?

标签: css twitter-bootstrap mobile menu


【解决方案1】:

这将有点棘手,因为创建者写道:

可惜菜单必须在按钮内

但是,嘿,这是纯粹的 CSS 魔法。

要添加的代码是

/*
 * This move all the navbar to right because the ul is inside the button
 */
#menuToggle{
    position:fixed;
    left: calc(100vw - 70px);
    top:calc(100vh - 50px);
}

/*
 * This will position the menu
 */
#menu{
    top: calc(-100vh + 50px);
    left: 70px;
    margin: 0;
    margin-top: -100px;
    height: 100vh;
}

/*
 * Fade menu from the right
 */
#menuToggle input:checked ~ ul
{
    transform: translate(-100%, 0);
    opacity: 1;
}

/*
 * Correct the overflow
 */
 html{
     max-width: 100vw;
     overflow-x: hidden;
 }

/*
 * Made by Erik Terwan
 * 24th of November 2015
 * All rights reserved
 *
 * Modified by Alessandro Lodi
 * 5th of August 2017
 *
 * If you are thinking of using this in
 * production code, beware of the browser
 * prefixes.
 */

body
{
  margin: 0;
  padding: 0;
  
  /* make it look decent enough */
  background: #232323;
  color: #cdcdcd;
  font-family: "Avenir Next", "Avenir", sans-serif;
}

a
{
  text-decoration: none;
  color: #232323;
  
  transition: color 0.3s ease;
}

a:hover
{
  color: tomato;
}

#menuToggle
{
  display: block;
  position: relative;
  top: 50px;
  left: 50px;
  
  z-index: 1;
  
  -webkit-user-select: none;
  user-select: none;
}

#menuToggle input
{
  display: block;
  width: 40px;
  height: 32px;
  position: absolute;
  top: -7px;
  left: -5px;
  
  cursor: pointer;
  
  opacity: 0; /* hide this */
  z-index: 2; /* and place it over the hamburger */
  
  -webkit-touch-callout: none;
}

/*
 * Just a quick hamburger
 */
#menuToggle span
{
  display: block;
  width: 33px;
  height: 4px;
  margin-bottom: 5px;
  position: relative;
  
  background: #cdcdcd;
  border-radius: 3px;
  
  z-index: 1;
  
  transform-origin: 4px 0px;
  
  transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
              background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
              opacity 0.55s ease;
}

#menuToggle span:first-child
{
  transform-origin: 0% 0%;
}

#menuToggle span:nth-last-child(2)
{
  transform-origin: 0% 100%;
}

/* 
 * Transform all the slices of hamburger
 * into a crossmark.
 */
#menuToggle input:checked ~ span
{
  opacity: 1;
  transform: rotate(45deg) translate(-2px, -1px);
  background: #232323;
}

/*
 * But let's hide the middle one.
 */
#menuToggle input:checked ~ span:nth-last-child(3)
{
  opacity: 0;
  transform: rotate(0deg) scale(0.2, 0.2);
}

/*
 * Ohyeah and the last one should go the other direction
 */
#menuToggle input:checked ~ span:nth-last-child(2)
{
  opacity: 1;
  transform: rotate(-45deg) translate(0, -1px);
}

/*
 * Make this absolute positioned
 * at the top left of the screen
 */
#menu
{
  position: absolute;
  width: 250px;
  margin: -100px 0 0 -50px;
  padding: 50px;
  padding-top: 125px;
  
  background: #ededed;
  list-style-type: none;
  -webkit-font-smoothing: antialiased;
  /* to stop flickering of text in safari */
  
  transform-origin: 0% 0%;
  //transform: translate(-100%, 0);
  
  transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}

#menu li
{
  padding: 10px 0;
  font-size: 22px;
}

/*
 * And let's fade it in from the left
 */
#menuToggle input:checked ~ ul
{
  transform: translate(-100%, 0);
  opacity: 1;
}

#menuToggle{
    position:fixed;
    left: calc(100vw - 70px);
    top:calc(100vh - 50px);
}

#menu{
    top: calc(-100vh + 50px);
    left: 70px;
    margin: 0;
    margin-top: -100px;
    height: 100vh;
}

html{
    max-width: 100vw;
    overflow-x: hidden;
}
<nav role="navigation">
  <div id="menuToggle">
    <!--
    A fake / hidden checkbox is used as click reciever,
    so you can use the :checked selector on it.
    -->
    <input type="checkbox" />
    
    <!--
    Some spans to act as a hamburger.
    
    They are acting like a real hamburger,
    not that McDonalds stuff.
    -->
    <span></span>
    <span></span>
    <span></span>
    
    <!--
    Too bad the menu has to be inside of the button
    but hey, it's pure CSS magic.
    -->
    <ul id="menu">
      <a href="#"><li>Home</li></a>
      <a href="#"><li>About</li></a>
      <a href="#"><li>Info</li></a>
      <a href="#"><li>Contact</li></a>
      <a href="https://erikterwan.com/" target="_blank"><li>Show me more</li></a>
    </ul>
  </div>
</nav>

【讨论】:

  • 哇,谢谢兄弟!你介意稍后(如果我不明白你做了什么)我问你一些问题吗?由于时间不够,我只是复制并粘贴了代码而没有分析它。再次感谢!
  • 是的,你可以问我你想要什么:)
猜你喜欢
  • 2017-09-03
  • 2021-06-27
  • 1970-01-01
  • 2015-09-30
  • 1970-01-01
  • 2014-12-06
  • 2019-11-05
  • 2020-10-31
  • 2021-05-26
相关资源
最近更新 更多