I have successfully implemented a navigation bar, but I am facing an issue where the 'menu toggle' button does not align on the right side of the screen when the screen width is 768px or less. Instead, it appears right after the image. (Refer to my example for clarification).
Is there a way to make the <label class="menu-icon">
float to the right of the page on screens smaller than 768px? I have attempted using 'float: right', but that disrupts the vertical alignment which needs to remain centered vertically.
My attempts below did not yield the desired outcome:
.nav-widget .header .menu-icon {
position: absolute;
right: 0px;
}
or
.nav-widget .header .menu-icon {
float: right;
}
.nav-widget {
box-shadow: 1px 1px 4px 0 rgba(0, 0, 0, 0.1);
width: 100%;
z-index: 9999;
}
.nav-widget .header {
display: table;
width: 100%;
position: relative;
}
.nav-widget .header .left-nav {
display: inline-block;
display: table-cell;
vertical-align: middle;
text-align: left;
}
.nav-widget .header .right-nav {
display: inline-block;
display: table-cell;
vertical-align: middle;
text-align: right;
}
/* How can I align this on the right? */
.nav-widget .header .menu-icon {
cursor: pointer;
vertical-align: middle;
display: none;
right: 0px;
}
.nav-widget .header .menu-icon .navicon {
background: #333;
display: block;
height: 2px;
position: relative;
transition: background 0.2s ease-out;
width: 18px;
}
.nav-widget .header .menu-icon .navicon:before,
.nav-widget .header .menu-icon .navicon:after {
background: #333;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all 0.2s ease-out;
width: 100%;
}
.nav-widget .header .menu-icon .navicon:before {
top: 5px;
}
.nav-widget .header .menu-icon .navicon:after {
top: -5px;
}
.nav-widget .header .menu-btn {
display: none;
}
.nav-widget .header .menu-btn:checked ~ .right-nav {
max-height: 240px !important;
display: block;
}
.nav-widget .header .menu-btn:checked ~ .right-nav > .widget {
display: block;
}
.nav-widget .header .menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.nav-widget .header .menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}
.nav-widget .header .menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.nav-widget .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
.nav-widget .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}
@media (max-width: 768px) {
.nav-widget .header .left-nav {
display: inline-block; /*table-cell;*/
}
.nav-widget .header .menu-icon {
display: inline-block; /*table-cell;*/
}
.nav-widget .header .right-nav {
clear: both;
max-height: 0 !important;
min-height: 0 !important;
overflow: hidden;
transition: max-height 0.2s ease-out;
padding: 0 !important;
display: none;
background-color: red;
text-align: center;
}
.nav-widget .header .right-nav a {
display: block;
}
}
<div class="nav-widget">
<nav class="header">
<div class="left-nav">
<img src="https://via.placeholder.com/140x100">
</div>
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<div class="right-nav">
<a href="#"><span>Press Me</span></a>
<a href="#"><span>Press Me</span></a>
</div>
</nav>
</div>
<p>The menu toggle button should be positioned on the right side of the page, not immediately after the image.</p>