I am building my first website and I would like to place my navigation menu on the right but I can't seem to figure it out. In my opinion the navigation menu bars being on the left can be irritating to the user. Your help would be appreciated.
CSS
nav .fa-solid{
display: none;
}
@media(max-width: 500px){
.nav-links ul li{
display: block;
}
.nav-links{
position: absolute;
background: #f44336;
height: 100vh;
width: 200px;
top: 0;
right: -200px;
text-align: left;
z-index: 2;
transition: 1s;
}
nav .fa-solid{
display: block;
color: #fff;
margin: 10px;
font-size: 22px;
cursor: pointer;
}
}
HTML
<body>
<section >
<nav>
<div id="navLinks">
<i onclick="hideMenu()"></i>
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="">MUSIC</a></li>
<li><a href="">ART</a></li>
<li><a href="">GAMES</a></li>
<li><a href="">MERCH</a></li>
<li><a href="">ABOUT</a></li>
</ul>
</div>
<i onclick="showMenu()"></i>
</nav>
CodePudding user response:
Try this out and display:flex
to nav
and remove position:absolute
as it just forces the things to happen. You can use flex
and I guess that's a better approach. You can change the style as per the size of the screen and placing it with flex
will help you further in your design.
nav{
display:flex;
justify-content:flex-end;
}
nav .fa-solid{
display: none;
}
@media(max-width: 500px){
.nav-links ul li{
display: block;
}
.nav-links{
background: #f44336;
height: 100vh;
width: 200px;
text-align: left;
z-index: 2;
transition: 1s;
}
nav .fa-solid{
display: block;
color: #fff;
margin: 10px;
font-size: 22px;
cursor: pointer;
}
}
<nav>
<div id="navLinks">
<i onclick="hideMenu()"></i>
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="">MUSIC</a></li>
<li><a href="">ART</a></li>
<li><a href="">GAMES</a></li>
<li><a href="">MERCH</a></li>
<li><a href="">ABOUT</a></li>
</ul>
</div>
<i onclick="showMenu()"></i>
</nav>
CodePudding user response:
well you can try something like this
Source: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_topnav_right
code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #04AA6D;
color: white;
}
.topnav-right {
float: right;
}
</style>
</head>
<body>
<div >
<div >
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#search">Search</a>
<a href="#about">About</a>
</div>
</div>
<div style="padding-left:16px">
<h2>Top Navigation with Right Aligned Links</h2>
<p>Some content..</p>
</div>
</body>
</html>