Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS How to move hamburger menu icon to the right side of header?

kabir07

Coder
I want to move my hamburger menu icon on the mobile to the right side of the screen. Currently it resides on the left. I have tried but couldn't find a way to move it to right. As I am not a CSS and HTML expert, I really need to do this but i am stuck. I am posting the html and CSS code below please have look. Can anyone suggest a way to do this?

CSS:
* {
  padding: 0;
  margin: 0;
}

nav {
  background-color: #91cfa1;
  height: 50px;
  padding: 0 16px;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  /* fade in checked menu */
}
nav .m-menu__checkbox {
  display: none;
}
nav label.m-menu__toggle {
  cursor: pointer;
}
nav .m-menu {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 450px;
  width: calc(100vw - 30px);
  height: 100%;
  -moz-transform: translate3d(-450px, 0, 0);
  -o-transform: translate3d(-450px, 0, 0);
  -ms-transform: translate3d(-450px, 0, 0);
  -webkit-transform: translate3d(-450px, 0, 0);
  transform: translate3d(-450px, 0, 0);
  -moz-transition: transform 0.35s;
  -o-transition: transform 0.35s;
  -webkit-transition: transform 0.35s;
  transition: transform 0.35s;
  z-index: 1;
  overflow: hidden;
  background-color: #fff;
}
nav .m-menu__overlay {
  background-color: rgba(103, 103, 103, 0.5);
  position: absolute;
  top: 0;
  width: 100%;
  bottom: 0;
  z-index: 1;
  display: none;
}
nav .m-menu__header {
  padding: 0 16px;
  height: 50px;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: space-around;
  justify-content: space-around;
  -ms-flex-pack: space-around;
  -webkit-align-items: center;
  align-items: center;
  border-bottom: 1px solid #e8e8e8;
}
nav .m-menu__header span {
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  width: 100%;
}
nav .m-menu .m-menu {
  -moz-transform: translate3d(480px, 0, 0);
  -o-transform: translate3d(480px, 0, 0);
  -ms-transform: translate3d(480px, 0, 0);
  -webkit-transform: translate3d(480px, 0, 0);
  transform: translate3d(480px, 0, 0);
}
nav .m-menu ul {
  height: 100%;
  overflow-y: auto;
}
nav .m-menu ul li a, nav .m-menu ul li label {
  display: block;
  text-align: left;
  padding: 0 15px;
  line-height: 47px;
  text-decoration: none;
  color: #333;
  cursor: pointer;
  font-size: 1rem;
  border-bottom: 1px solid #e8e8e8;
  position: relative;
}
nav .m-menu ul li label.a-label__chevron::after {
  content: "";
  position: absolute;
  display: inline-block;
  height: 10px;
  width: 10px;
  border-color: #333;
  border-style: solid;
  border-width: 1px 1px 0 0;
  -moz-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  top: 50%;
  margin-top: -5px;
  right: 16px;
}
nav .m-menu ul li .-invisible {
  border-bottom: 0;
}
nav .m-menu .m-menu label.m-menu__toggle {
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  border-bottom: 0;
  padding: 0;
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
}
nav .m-menu__checkbox:checked ~ .m-menu__overlay {
  display: block;
}
nav .m-menu__checkbox:checked ~ .m-menu {
  -moz-transform: translate3d(0, 0, 0);
  -o-transform: translate3d(0, 0, 0);
  -ms-transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}

.wrapper {
  width: 480px;
  height: 667px;
  margin: 0 auto;
  overflow: hidden;
  background-color: #fff;
  position: relative;
}

body {
  background-color: #f1f1f1;
  padding: 0;
  margin: 0;
  font-family: sans-serif;
}

HTML:
<div class="wrapper">
  <nav>
    <input type="checkbox" id="menu" name="menu" class="m-menu__checkbox">
    <label class="m-menu__toggle" for="menu">
      <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
    </label>
    <label class="m-menu__overlay" for="menu"></label>
 
    <div class="m-menu">
      <div class="m-menu__header">
        <label class="m-menu__toggle" for="menu">
          <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
            <line x1="18" y1="6" x2="6" y2="18"></line>
            <line x1="6" y1="6" x2="18" y2="18"></line>
          </svg>
        </label>
        <span>MENU</span>
      </div>
      <ul>
        <li><label>Item 1</label></li>
        <li>
          <label class="a-label__chevron" for="item-2">Item 2</label>
          <input type="checkbox" id="item-2" name="item-2" class="m-menu__checkbox">
          <div class="m-menu">
            <div class="m-menu__header">
              <label class="m-menu__toggle" for="item-2">
                <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
                  <path d="M19 12H6M12 5l-7 7 7 7"/>
                </svg>
              </label>
              <span>Item 2</span>
            </div>
            <ul>
              <li><label>Item 2.1</label></li>
              <li><label>Item 2.2</label></li>
              <li>
                <label class="a-label__chevron" for="item-2-3">Item 2.3</label>
                <input type="checkbox" id="item-2-3" name="item-2" class="m-menu__checkbox">
                <div class="m-menu">
                  <div class="m-menu__header">
                    <label class="m-menu__toggle" for="item-2-3">
                      <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
                        <path d="M19 12H6M12 5l-7 7 7 7"/>
                      </svg>
                    </label>
                    <span>Item 2.3 </span>
                  </div>
                  <ul>
                    <li><label>Item 2.3.1</label></li>
                    <li><label>Item 2.3.2</label></li>
                    <li><label>Item 2.3.3</label></li>
                    <li><label>Item 2.3.4</label></li>
                    <li><label>Item 2.3.5</label></li>
                  </ul>               
              </li>
              <li><label>Item 2.4</label></li>
              <li><label>Item 2.5</label></li>
              <li><label>Item 2.6</label></li>
              <li><label>Item 2.7</label></li>
              <li><label>Item 2.8</label></li>
              <li><label>Item 2.9</label></li>
          </div>
        </li>
        <li><label>Item 3</label></li>
        <li><label>Item 4</label></li>
        <li><label>Item 5</label></li>
        <li><label>Item 6</label></li>
      </ul> 
    </div>
  </nav>
</div>
 
I want to move my hamburger menu icon on the mobile to the right side of the screen. Currently it resides on the left. I have tried but couldn't find a way to move it to right. As I am not a CSS and HTML expert, I really need to do this but i am stuck. I am posting the html and CSS code below please have look. Can anyone suggest a way to do this?

CSS:
* {
  padding: 0;
  margin: 0;
}

nav {
  background-color: #91cfa1;
  height: 50px;
  padding: 0 16px;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  /* fade in checked menu */
}
nav .m-menu__checkbox {
  display: none;
}
nav label.m-menu__toggle {
  cursor: pointer;
}
nav .m-menu {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 450px;
  width: calc(100vw - 30px);
  height: 100%;
  -moz-transform: translate3d(-450px, 0, 0);
  -o-transform: translate3d(-450px, 0, 0);
  -ms-transform: translate3d(-450px, 0, 0);
  -webkit-transform: translate3d(-450px, 0, 0);
  transform: translate3d(-450px, 0, 0);
  -moz-transition: transform 0.35s;
  -o-transition: transform 0.35s;
  -webkit-transition: transform 0.35s;
  transition: transform 0.35s;
  z-index: 1;
  overflow: hidden;
  background-color: #fff;
}
nav .m-menu__overlay {
  background-color: rgba(103, 103, 103, 0.5);
  position: absolute;
  top: 0;
  width: 100%;
  bottom: 0;
  z-index: 1;
  display: none;
}
nav .m-menu__header {
  padding: 0 16px;
  height: 50px;
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: space-around;
  justify-content: space-around;
  -ms-flex-pack: space-around;
  -webkit-align-items: center;
  align-items: center;
  border-bottom: 1px solid #e8e8e8;
}
nav .m-menu__header span {
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  width: 100%;
}
nav .m-menu .m-menu {
  -moz-transform: translate3d(480px, 0, 0);
  -o-transform: translate3d(480px, 0, 0);
  -ms-transform: translate3d(480px, 0, 0);
  -webkit-transform: translate3d(480px, 0, 0);
  transform: translate3d(480px, 0, 0);
}
nav .m-menu ul {
  height: 100%;
  overflow-y: auto;
}
nav .m-menu ul li a, nav .m-menu ul li label {
  display: block;
  text-align: left;
  padding: 0 15px;
  line-height: 47px;
  text-decoration: none;
  color: #333;
  cursor: pointer;
  font-size: 1rem;
  border-bottom: 1px solid #e8e8e8;
  position: relative;
}
nav .m-menu ul li label.a-label__chevron::after {
  content: "";
  position: absolute;
  display: inline-block;
  height: 10px;
  width: 10px;
  border-color: #333;
  border-style: solid;
  border-width: 1px 1px 0 0;
  -moz-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  top: 50%;
  margin-top: -5px;
  right: 16px;
}
nav .m-menu ul li .-invisible {
  border-bottom: 0;
}
nav .m-menu .m-menu label.m-menu__toggle {
  display: -ms-flexbox;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  border-bottom: 0;
  padding: 0;
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
}
nav .m-menu__checkbox:checked ~ .m-menu__overlay {
  display: block;
}
nav .m-menu__checkbox:checked ~ .m-menu {
  -moz-transform: translate3d(0, 0, 0);
  -o-transform: translate3d(0, 0, 0);
  -ms-transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}

.wrapper {
  width: 480px;
  height: 667px;
  margin: 0 auto;
  overflow: hidden;
  background-color: #fff;
  position: relative;
}

body {
  background-color: #f1f1f1;
  padding: 0;
  margin: 0;
  font-family: sans-serif;
}

HTML:
<div class="wrapper">
  <nav>
    <input type="checkbox" id="menu" name="menu" class="m-menu__checkbox">
    <label class="m-menu__toggle" for="menu">
      <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
    </label>
    <label class="m-menu__overlay" for="menu"></label>
 
    <div class="m-menu">
      <div class="m-menu__header">
        <label class="m-menu__toggle" for="menu">
          <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
            <line x1="18" y1="6" x2="6" y2="18"></line>
            <line x1="6" y1="6" x2="18" y2="18"></line>
          </svg>
        </label>
        <span>MENU</span>
      </div>
      <ul>
        <li><label>Item 1</label></li>
        <li>
          <label class="a-label__chevron" for="item-2">Item 2</label>
          <input type="checkbox" id="item-2" name="item-2" class="m-menu__checkbox">
          <div class="m-menu">
            <div class="m-menu__header">
              <label class="m-menu__toggle" for="item-2">
                <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
                  <path d="M19 12H6M12 5l-7 7 7 7"/>
                </svg>
              </label>
              <span>Item 2</span>
            </div>
            <ul>
              <li><label>Item 2.1</label></li>
              <li><label>Item 2.2</label></li>
              <li>
                <label class="a-label__chevron" for="item-2-3">Item 2.3</label>
                <input type="checkbox" id="item-2-3" name="item-2" class="m-menu__checkbox">
                <div class="m-menu">
                  <div class="m-menu__header">
                    <label class="m-menu__toggle" for="item-2-3">
                      <svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
                        <path d="M19 12H6M12 5l-7 7 7 7"/>
                      </svg>
                    </label>
                    <span>Item 2.3 </span>
                  </div>
                  <ul>
                    <li><label>Item 2.3.1</label></li>
                    <li><label>Item 2.3.2</label></li>
                    <li><label>Item 2.3.3</label></li>
                    <li><label>Item 2.3.4</label></li>
                    <li><label>Item 2.3.5</label></li>
                  </ul>              
              </li>
              <li><label>Item 2.4</label></li>
              <li><label>Item 2.5</label></li>
              <li><label>Item 2.6</label></li>
              <li><label>Item 2.7</label></li>
              <li><label>Item 2.8</label></li>
              <li><label>Item 2.9</label></li>
          </div>
        </li>
        <li><label>Item 3</label></li>
        <li><label>Item 4</label></li>
        <li><label>Item 5</label></li>
        <li><label>Item 6</label></li>
      </ul>
    </div>
  </nav>
</div>
HI there,

If you're just looking to move the menu to the right side, you could do
CSS:
float: right;
 

New Threads

Buy us a coffee!

Back
Top Bottom