How would I set the right margin automatically to the end of the "contact" tab and not at the end of the page?
nav{
position: relative;
margin-right: auto;
width: auto;
height: 50px;
background: #f563ff;
border-radius: 8px;
font-size: 0;
box-shadow: 0 2px 3px 0 rgba(0,0,0,.1);
CodePudding user response:
If you want to set a margin rigth only to "contact" select its class and aplly it. If it doesn't have class so use nt
ul{
background-color: aquamarine;
text-align: end;
}
li{
display: inline;
}
li:nth-child(4){
margin-right: 50px;
background-color:bisque
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./index.css">
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>contact</li>
</ul>
</body>
</html>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
You can use last-child properties and work well for the last menu
ul li:last:child{padding-right:30px;}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Project</title>
<style>
ul.main-menu li:last-child{padding-right:30px !important; }
</style>
</head>
<body>
<nav>
<ul class="main-menu">
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>contact</li>
</ul>
</nav>
</body>
</html>