-1

.nav {
  display: flex;
  background: dodgerblue;
  position: sticky;
  top: 0;
}

.links-container {
  display: flex;
  float: right;
}
<header class="nav">
  <h1 class="logo">Learn to code</h1>
  <div class="links-container">
    <p>test</p>
    <p>test</p>
    <p>test</p>
    <p>test</p>
    <p>test</p>
  </div>
</header>

I have tried position relative on the link container and that didn't work either.

lawrence-witt
  • 8,094
  • 3
  • 13
  • 32
Joeman
  • 241
  • 2
  • 9

3 Answers3

1

Floats really aren't the best way to do this anymore. Try flexbox!

* {
margin: none;
padding: none;
box-sizing: border-box;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

header nav {
  display: flex;
}

header nav p {
  margin: 0 10px;
}
<header>
  <h1 class="logo">Learn to code</h1>
  <nav>
    <p>test</p>
    <p>test</p>
    <p>test</p>
    <p>test</p>
    <p>test</p>
  </nav>
</header>
Jon Lothar
  • 186
  • 1
  • 7
1

Here's what I think you might want to do:

.nav{
  display:flex;
  background:dodgerblue;
  position:sticky;
  top:0;
}
.links-container{
  display:flex;
  flex:1;
  align-items:center;
  justify-content:flex-end;
}
<header class='nav'>
  <h1 class='logo'>Learn to code</h1>
  <div class='links-container'>
    <p>test</p>
    <p>test</p>
    <p>test</p>
    <p>test</p>
    <p>test</p>
  </div>
</header>
StackSlave
  • 10,613
  • 2
  • 18
  • 35
0

Float properties are ignored in flex containers.

In your case auto margins will be the right fit

.links-container {
  display: flex;
  margin-left: auto;
}
ndiecodes
  • 1
  • 2