1

I have my header in my html with three elements an image representing the logo, the title, and some icons, in that order. I already have them centered using flexbox but I want to keep the logo in the leftmost part of the screen and the icons on the opposite side, while keeping the title in the middle, this is my html:

.title {
  display: flex;
  align-items: center;
  justify-content: center;
}

.title .logo {
  justify-content: flex-start;
}
<header>
  <div class="title">
    <img class="logo" src="./img/logo.png" alt="" width="100" height="100">
    <h1 class="subtitle">Lorem ipsum dolor</h1>
    <div class="socials">
      <a href="">
        <i class="fab fa-facebook fa-2x"></i>
      </a>
      <a href="">
        <i class="fab fa-instagram fa-2x"></i>
      </a>
    </div>
  </div>
</header>

I have tried expanding the margin of the title, but it doesn't look good and here's a screenshot of what the header looks like:

Alexander Nied
  • 12,804
  • 4
  • 25
  • 45

2 Answers2

1

Just make a little change in your css file, Change justify-content to space-between for your title selector

.title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
Alexander Nied
  • 12,804
  • 4
  • 25
  • 45
Gulshan Aggarwal
  • 954
  • 1
  • 7
  • 13
0

You can use flexbox auto-margins to achieve this effect:

.title {
  display: flex;
  align-items: center;
  justify-content: center;
}

.title .logo {
  justify-content: flex-start;
}

.logo {
  margin-right: auto;
}

.socials {
  margin-left: auto;
}
<header>
  <div class="title">
    <img class="logo" src="./img/logo.png" alt="" width="100" height="100">
    <h1 class="subtitle">Lorem ipsum dolor</h1>
    <div class="socials">
      <a href="">
        <i class="fab fa-facebook fa-2x"></i>
        fb
      </a>
      <a href="">
        <i class="fab fa-instagram fa-2x"></i>
        insta
      </a>
    </div>
  </div>
</header>
Alexander Nied
  • 12,804
  • 4
  • 25
  • 45