search

Home  >  Q&A  >  body text

justify-content: space-between in Flexbox doesn't seem to work

I've tried changing a lot of things in the CSS using classes and IDs, but there doesn't seem to be any way to get both images to be on the far side of the screen (logo on the far left, profile on the far right).

Tried a lot of different things like text-align and different justify-contents but nothing seems to work.

This is the code:

.top-nav {
  display: flex;
  position: absolute;
  background-color: blue;
  opacity: 0.5;
  height: 10%;
  top: 0;
  width: 100%;
  left: 0;
  padding: 0;
  border: 0;
  margin: 0;
  list-style: none;
}

.top-nav div {
  display: flex;
  justify-content: space-between;
  height: 100%;
  margin: 0px;
  padding: 0;
  border: 0;
  margin: 0;
}
<div class="top-nav">
  <div style="flex-grow: 1"><img src="/textures/logo.svg"></div>
  <div style="flex-grow: 1"><img src="/textures/profile.svg"></div>
</div>

P粉511749537P粉511749537291 days ago477

reply all(1)I'll reply

  • P粉491421413

    P粉4914214132024-03-22 20:21:09

    justify-content now does nothing because it is set on a div without display:flex. If you want separate divs for the images, put justify-content:space- Between on the div that contains them, i.e. the top navigation div.

    reply
    0
  • Cancelreply