0

I would like have a center navbar and in right have one element like that : example of I want

Actually I have made this:

* {
  margin: 0;
  padding: 0;
}

header {
  position: fixed;
  height: 35px;
  width: 100vw;
  z-index: 2;
  background-color: rgba(0, 0, 0, 1);
}

.nav {
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  height: 100%;
  align-items: center;
  text-transform: uppercase;
}

li {
  list-style: none;
}

.center {
  text-align: center;
  display: flex;
}

.right {
  right: 0;
  text-align: right;
}

.nav .text1 {
  color: #f2f2f2;
  padding: 15px 35px;
  text-decoration: none;
  font-size: 12px;
}
<header>
  <div class="nav">
    <div class="center">
      <li><a class="text1" href="#">one</a></li>
      <li><a class="text1" href="#">two</a></li>
      <li><a class="text1" href="#">tree</a></li>
    </div>
    <div class="right">
      <li><a class="text1" href="#">four</a></li>
    </div>
  </div>
</header>

How I can put the "Four" element in right?

j08691
  • 204,283
  • 31
  • 260
  • 272
DisplayYet
  • 19
  • 7

1 Answers1

1

You were very close, but forgot to set the position of the .right element to absolute. right: 0 won't do anything to a element with default (aka static) positioning. https://developer.mozilla.org/en-US/docs/Web/CSS/position

* {
  margin: 0;
  padding: 0;
}

header {
  position: fixed;
  height: 35px;
  width: 100vw;
  z-index: 2;
  background-color: rgba(0, 0, 0, 1);
}

.nav {
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  height: 100%;
  align-items: center;
  text-transform: uppercase;
}

li {
  list-style: none;
}

.center {
  text-align: center;
  display: flex;
}

.right {
  position: absolute;
  right: 0;
  text-align: right;
}

.nav .text1 {
  color: #f2f2f2;
  padding: 15px 35px;
  text-decoration: none;
  font-size: 12px;
}
<header>
  <div class="nav">
    <div class="center">
      <li><a class="text1" href="#">one</a></li>
      <li><a class="text1" href="#">two</a></li>
      <li><a class="text1" href="#">tree</a></li>
    </div>
    <div class="right">
      <li><a class="text1" href="#">four</a></li>
    </div>
  </div>
</header>
Caleb Bertrand
  • 410
  • 5
  • 15