如何将菜单与桌面右侧对齐?

时间:2018-08-03 20:01:25

标签: html css

我有一个网站菜单,该菜单当前位于浏览器的左侧。我尝试在浏览器的右侧对齐。

这是演示: here

我想要的只是将孔菜单放在浏览器屏幕的右侧,然后将其对齐。当前显示在左侧。

正在尝试: https://i.stack.imgur.com/D0y00.png

html代码:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css">
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">


<header>
    <span class="toggle-button">
        <div class="menu-bar menu-bar-top"></div>
        <div class="menu-bar menu-bar-middle"></div>
        <div class="menu-bar menu-bar-bottom"></div>
    </span>
    <div class="menu-wrap">
        <div class="menu-sidebar">
            <ul class="menu">
                <li><a href="#">Home</a></li>
                <li class="children"><a href="#">News</a>
                    <span class="arrow"></span>
                    <ul class="child-menu ">
                        <li><a href="#">Link 1</a></li>
                        <li><a href="#">Link 2</a></li>
                        <li><a href="#">link 3</a></li>
                    </ul>
                </li>
                <li class="children"><a href="#">Contact</a>
                    <span class="arrow"></span>
                    <ul class="child-menu ">
                        <li><a href="#">Link 1</a></li>
                        <li><a href="#">Link 2</a></li>
                        <li><a href="#">link 3</a></li>
                    </ul>
                </li>
                <li class="children"><a href="#">About</a>
                    <span class="arrow"></span>
                    <ul class="child-menu ">
                        <li><a href="#">Link 1</a></li>
                        <li><a href="#">Link 2</a></li>
                        <li><a href="#">link 3</a></li>
                    </ul>
                </li>
                <li><a href="#">FAQ</a></li>
                <li><a href="#">Services</a></li>

            </ul>           
        </div>
    </div>
</header>
<div class="wrapper" style="background-color:;padding:15px;">
    <section class="text"  style="background-color:;">
        <h2 class="heading" id="headings" style="background-color:;text-align:center;">Three Line Menu & CSS Transitions</h2>

        <p class="buttons" style="min-width: 200px;margin:auto;background-color:;text-align:center;">
              <a href="#"  style="background-color:;" class="btn_one">Learn More</a>

        </p>
    </section>
</div>

CSS:

html {


        background: url(https://s33.postimg.cc/tm1vd9yy7/Background_2.jpg);
        background-attachment:fixed;
        background-repeat: no-repeat;
        background-size: cover;  

     }

.btn_one {

text-decoration: none;
color: white;
font-weight: 100;
border: 1px #fbbc05 solid;
padding: 1em 3em;
border-radius: 100px;   
}

a {
text-decoration: none;
}
ul {
  padding-left: 0;
}
li {
list-style: none;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Montserrat', Arial, serif;
}
::selection {
background-color: #EBEBF2;
color: #83828D;
 }


/* ==================================== */
  /*      Navigaton Menu        */
/* ==================================== */

.menu-wrap {
 background-color: #625871;
position: fixed;
top: 0;
height: 100%;
width: 280px;
margin-left: -280px;
font-size: 1em;
font-weight: 700;
overflow: auto;
transition: .25s;
z-index: 10;
}
.menu-show {
margin-left: 0;
box-shadow: 4px 2px 15px 1px #262424;
}



.menu-sidebar {
margin: 75px 0 80px 10px;
position: relative;
top: 70px;
}
.menu-sidebar li {
padding: 18px 22px 0;
}
.menu-sidebar li > a {
color: #f3f3f3;
font-size: 1.18em;
position: relative;
}
.menu-sidebar li > a::after {
content: "";
display: block;
height: 0.15em;
position: absolute;
top: 100%;
width: 100%;
left: 50%;
transform: translate(-50%);
background-image: linear-gradient(to right, transparent 50.3%, #FFFA3B 50.3%);
transition: background-position .2s .1s ease-out;
background-size: 200% auto;
}
.menu-sidebar li > a:hover::after {
background-position: -100% 0;
}
.menu-sidebar .children {
position: relative;
}
.menu-sidebar .children .child-menu {
display: none;
}
.arrow::after {
content: "\f107";
font-family: 'FontAwesome';
padding: 10px;
color: #FFFA3B;
position: relative;
}
.arrow:hover::after {
cursor: pointer;
color: #fff;
}
.arrow:active::after {
top: 2px;
}


 /*Hamburger Button*/
.toggle-button {
position: fixed;
width: 44px;
height: 40px;
top: 50px;
left: 40px;
padding: 4px;
transition: .25s;
z-index: 15;
}
.toggle-button:hover {
cursor: pointer;
}

.toggle-button .menu-bar {
position: absolute;
border-radius: 2px; 
transition: .5s;
}
.toggle-button .menu-bar-top {
border: 4px solid #fff;
border-bottom: none;
top: 0;
width: 80%;
}
.toggle-button .menu-bar-middle {
height: 4px;
background-color: #fff;
margin-top: 7px;
margin-bottom: 7px;
width: 40%;
top: 4px;
}
.toggle-button .menu-bar-bottom {
border: 4px solid #fff;
border-top: none;
top: 22px;
width: 60%;
}
.toggle-button:hover div 
{
width: 80%;
}




.button-open {
left: 25px;
}
.button-open .menu-bar-top {
border-color: #fff;
transform: rotate(45deg) translate(8px, 8px);
transition: .5s;
}
.button-open .menu-bar-middle {
background-color: #fff;
transform: translate(230px);
transition: .1s ease-in;
opacity: 0;
}
.button-open .menu-bar-bottom {
border-color: #fff;
transform: rotate(-45deg) translate(7px, -7px);
transition: .5s;
}



/* Text Block */
.wrapper {
width: 40%;
margin: 100px auto 0;
color: #83828D;
 }
.wrapper .text {
padding: 30px;
 }
.wrapper .text .heading {
margin-bottom: 40px;
font-size: 2em;
color:#fff;
  }
 .wrapper .text p {
line-height: 1.6em;
  }
  .wrapper .text .buttons {
margin-top: 40px;
  }

/* Buttons */
.wrapper .buttons .button {
display: inline-block;
margin-right: 20px;
padding: 20px 25px;
border-radius: 2em;
background-color: #70CE64;
color: #fff;
font-size: .9em;
font-weight: 700;
transition: background-color .3s;
  }
 .wrapper .buttons .button-secondary {
background-color: #FF6746;
  }
 .wrapper .buttons .button-primary:hover {
 background-color: #84D07A;
  }
  .wrapper .buttons .button-secondary:hover {
  background-color: #FF7D60;
 }

  /*Active state for the buttons*/

    .wrapper .buttons .button-primary:active {
      background-color: #70CE64;
  }
   .wrapper .buttons .button-secondary:active {
      background-color: #FF6746;
   }

/*Icons*/
.wrapper .buttons .button span {
position: relative;
display: inline-block;
padding-right: 20px;
}
.wrapper .buttons .button span::after {
position: absolute;
font-family: "FontAwesome";
right: -3px;
font-size: 14px;
top: 0;
transition: top .3s, right .3s;
}
.wrapper .buttons .button-primary span::after {
content: "\f019";
  }
 .wrapper .buttons .button-secondary span::after {
content: "\f178";
 }
  /*Slight icons animation*/
    .wrapper .buttons .button-primary:hover span::after {
    top: 4px;
     }
  .wrapper .buttons .button-secondary:hover span::after {
right: -6px;
 }

 @media screen and (max-width: 480px) {

#headings{
margin-bottom:20px;
font-size: 18px;
color:#fff;
}

.btn_one {
text-decoration: none;
color: #fff;
font-size:12px;
font-weight: 100;
border: 1px #fbbc05 solid;
padding: 8px 23px;
border-radius: 100px;
}

ul {
padding-left: 35px;
}
.menu-sidebar li
{
padding:0;
}   

.menu-wrap {

width: 200px;

}   

}

脚本:

$(document).ready(function() {

var $toggleButton = $('.toggle-button'),
    $menuWrap = $('.menu-wrap'),
    $sidebarArrow = $('.arrow');

// Hamburger button

$toggleButton.on('click', function() {
    $(this).toggleClass('button-open');
    $menuWrap.toggleClass('menu-show');
});

// Sidebar navigation arrows

$sidebarArrow.click(function() {
    $(this).next().slideToggle(300);
});

});

以下是供参考的源代码https://nofile.io/f/9bKHsuOoUza/source_code_new.zip

有人可以引导我吗?任何输入表示赞赏。 非常感谢。

1 个答案:

答案 0 :(得分:1)

将切换按钮更改为:

默认值:

.toggle-button {
    position: fixed;
    width: 44px;
    height: 40px;
    top: 50px;
    left: auto;
    padding: 4px;
    transition: .25s;
    z-index: 15;
    right: 40px;
}

打开:

.button-open {
    left: auto;
    right: 25px;
}

然后将菜单更改为:

关闭:

.menu-wrap {
    background-color: #00000030;
    position: fixed;
    top: 0;
    height: 100%;
    width: 240px;
    margin-left: 0;
    right: -280px;
    font-size: 1em;
    font-weight: 700;
    overflow: auto;
    transition: .25s;
    z-index: 10;
    left: auto;
}

打开:

.menu-show {
    left: auto;
    right: 0;
    margin-left: 0;
    box-shadow: 4px 2px 15px 1px #080707;
}

那样简单!