Objective:
The goal is to adjust the position of the navigation bar items using padding or margin as indicated in red:
https://i.sstatic.net/5vYTc.png
Issue
I noticed that applying a right padding or margin affects the collapsed (on mobile screen) list items with additional right margin or padding.
Here's an exaggerated example of excessive padding:
https://i.sstatic.net/KrKpC.png
Desired Outcome:
This is the desired layout:
https://i.sstatic.net/4g9fL.png
And, ensuring centered collapsed list items in responsive mode:
https://i.sstatic.net/XE8hm.png
Code Snippet:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 20px;
}
.navbar {
background-color: black !important;
}
.navbar .navbar-collapse li{
text-align: center;
margin-bottom: 20px;
}
.navbar-nav > li{
padding-right:30px;
}
.navbar li a {
text-decoration: none;
text-transform: uppercase;
font-size: 70%;
color: #000;
}
.navbar ul li a {
position: relative;
z-index: 1;
padding: 15px;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8>
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Vollkorn&display=swap" rel="stylesheet">
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-light">
<button class="navbar-toggler">
<span class="navbar-toggler-icon" data-toggle="collapse" data-target="#navbarMenu"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarMenu">
<ul class="navbar-nav">
<li class="nav-item"><a href="#">Home</a></li>
<li class="nav-item"><a href="#">About me</a></li>
<li class="nav-item"><a href="#">Projects</a></li>
<li class="nav-item"><a href="#">Contact me</a></li>
</ul>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56868883889d808cc68ec7e6f98689079989952af848882fd918c8a">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>
Inquiry
What would be an effective solution to achieve the specified design outcome?