I’m trying to make a floating island navbar, and I want all the links to go to the right of my container, but it’s not working. I tried putting it in my parent container but it just messed up the other styling.
.nav {
display:flex;
flex-direction: row;
line-height: 20px;
}
.island{
position: absolute;
display:flex;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: var(--primary);
z-index: 100;
width:35%;
border-radius: 100px;
padding:10px;
}
.island img{
width: 50px;
}
.linkcontainer a{
margin:20px;
color:white;
font-size: 14px;
height:100%;
justify-content: right;
}
<div class = "container">
<div class = "announcment"></div>
<div class = "Main">
<header>
<div class = "nav">
<div class = "shorten">
<div class = "main">
<div class = "island" >
<img src = "Images/Logo.png">
<div class = "links">
<div class = "linkcontainer">
<a>Link</a>
<a>Link</a>
<a>Link</a>
<a>BTN</a>
<a>BTN</a>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
</div>
</div>
I’ve only been coding for a year now so I don’t really know much.
3
Answers
To align the links to the right within the island, you can adjust the flexbox properties within the .linkcontainer.
Add this to your link-container class
.linkcontainer{ text-align: right }
Just use
flex
display withcolumn
value forflex-direction
.For child items (
a
elements) setmargin-left: auto
for it to position items on the right side (it will expand left margin to take rest of space).EDIT
Maybe you could add
display:block;
to.linkcontainer a
selector. I also changed color of links to default to make them visible.