Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Floating right doesn't move element to right side in a flexbox

* {
  margin: 0;
  padding: 0;
}

.background-image {
  background-image: url("https://solscan.io/static/media/banner-header-1.c1e47687b38c8afc4f948ebd7004acf8.svg");
  background-repeat: no-repeat;
  background-position: center top;
  height: clamp(150px, 15vh, 20vh);
  width: 100vw;
  background-size: cover;
  position: absolute;
  top: 0;
  right: 0;
  z-index: - 1;
}

.nav-bar {
  position: relative;
  z-index: 2;
  margin: 1.2rem 0.8rem;
  display: flex;
}

.logo {
  display: flex;
  float: right;
  /* margin-left: auto; */
}

i {
  font-size: 29px;
  color: white;
}
<!DOCTYPE html>

<html lang="en">

<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer"
  />
  <title>Page title</title>
</head>

<body>
  <div class="background-image"></div>
  <header class="header">
    <nav class="nav-bar">
      <img src="https://solscan.io/static/media/logo-solana-scan.ae03f445fd27dddc90c859d8728cbb44.svg">
      <div class="logo">
        <!-- <img src="sol.svg"> -->
        <i class="fa-solid fa-bars"></i>
      </div>
    </nav>
  </header>
</body>

</html>

I wanted to float class logo to right side of flexbox using float right but it’s not actually moving from the place and I cannot find the reason why would be good if anyone could explain me the reason.

I used margin-left: auto; to push the div to right side but I still need to learn the reason why float didn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

.nav-bar {
  position: relative;
  z-index: 2;
  margin: 1.2rem 0.8rem;
  display: flex;
justify-content: space-between
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading