Home > Back-end >  How can i move my logo to top left side in the header
How can i move my logo to top left side in the header

Time:09-19

I'm desiging an header for my college project where the logo is supposed to be in the top left corner. I have tried by using float property in CSS but it did not make reflection. How can I shift my logo to top left side in the header bar? I tried most of the time but code is not executed. [1]: https://i.stack.imgur.com/9SLRP.png

@import url('https://fonts.googleapis.com/css2?family=Montserrat Alternates:ital,wght@0,500;1,400&display=swap')

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  background-color: #F5F5F5;
}

li,
a,
button {
  font-family: "Montserrat", sans-serif;
  font-weight: 500;
  font-size: 16px;
  color: #000000;
  text-decoration: none;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px 10%;
  background: linear-gradient(rgba(165, 246, 144, 0.3) 0%, rgba(158, 249, 216, 0.63) 100%);
  height: 56px;
}

p {
  position: absolute;
  width: 584px;
  height: 67px;
  left: 232px;
  top: 25px;
  text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
  background: url(pharmapp.png);
  align-items: center;
  font-family: 'Montserrat';
  font-style: italic;
  font-weight: 400;
  font-size: 16px;
  line-height: 34px;
  color: #000000;
}

.logo {
  position: relative;
  float: left;
  margin-block-start: 10px;
  background: url(pharmapp.png);
  height: 122px;
  left: 20px;
  top: 0px;
  bottom: 40px;
}
<header >
  <img  src="img/pharmapp.png" alt="logo">
  <p >Medcines on your Doorstep</p>
  <nav >
    <ul>
      <li><a href="#">Login</a></li>
      <li><a href="#">SignUp</a></li>
      <li><a href="#">About</a></li>
    </ul>
  </nav>
  <a  href="#" <button>Contact</button></a>
</header>

CodePudding user response:

Your header has a padding: 30px 10, that means that the left and right side of the header receive a 10% padding, then in your .logo you are making the start position be 20px from the left.

A way to "fix" it would be to make the left of the .logo start in a negative position by left: calc(-10% 20px);

@import url('https://fonts.googleapis.com/css2?family=Montserrat Alternates:ital,wght@0,500;1,400&display=swap') * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  background-color: #F5F5F5;
}

li,
a,
button {
  font-family: "Montserrat", sans-serif;
  font-weight: 500;
  font-size: 16px;
  color: #000000;
  text-decoration: none;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px 10%;
  background: linear-gradient(rgba(165, 246, 144, 0.3) 0%, rgba(158, 249, 216, 0.63) 100%);
  height: 56px;
}

p {
  position: absolute;
  width: 584px;
  height: 67px;
  left: 232px;
  top: 25px;
  text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
  background: url(pharmapp.png);
  align-items: center;
  font-family: 'Montserrat';
  font-style: italic;
  font-weight: 400;
  font-size: 16px;
  line-height: 34px;
  color: #000000;
}

.logo {
  position: relative;
  float: left;
  margin-block-start: 10px;
  background: url(pharmapp.png);
  height: 122px;
  /*you can play with the numbers here*/
  left: calc(-10%   20px);
  top: 0px;
  bottom: 40px;
}
<header >
  <img  src="img/pharmapp.png" alt="logo">
  <p >Medcines on your Doorstep</p>
  <nav >
    <ul>
      <li><a href="#">Login</a></li>
      <li><a href="#">SignUp</a></li>
      <li><a href="#">About</a></li>
    </ul>
  </nav>
  <a  href="#"> <button>Contact</button></a>
</header>

CodePudding user response:

Just place your .logo element and your p tag in a div. It will sort itself out automatically.

You also forgot to close the a tag around the button.

Don't use float or absolute positioning in a layout, unless you know what you're doing...

@import url('https://fonts.googleapis.com/css2?family=Montserrat Alternates:ital,wght@0,500;1,400&display=swap')

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  background-color: #F5F5F5;
}

li,
a,
button {
  font-family: "Montserrat", sans-serif;
  font-weight: 500;
  font-size: 16px;
  color: #000000;
  text-decoration: none;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px 10%;
  background: linear-gradient(rgba(165, 246, 144, 0.3) 0%, rgba(158, 249, 216, 0.63) 100%);
  height: 56px;
}

/* p {
  position: absolute;
  width: 584px;
  height: 67px;
  left: 232px;
  top: 25px;
  text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
  background: url(pharmapp.png);
  align-items: center;
  font-family: 'Montserrat';
  font-style: italic;
  font-weight: 400;
  font-size: 16px;
  line-height: 34px;
  color: #000000;
} */

.logo {
/*  position: relative;
  float: left;*/
  margin-block-start: 10px;
  background: url(pharmapp.png);
  height: 122px;
/*  left: 20px;
  top: 0px;
  bottom: 40px;*/
}
<header >
  <div>
    <img  src="img/pharmapp.png" alt="logo">
    <p >Medicines on your Doorstep</p>
  </div>
  <nav >
    <ul>
      <li><a href="#">Login</a></li>
      <li><a href="#">SignUp</a></li>
      <li><a href="#">About</a></li>
    </ul>
  </nav>
  <a  href="#"><button>Contact</button></a>
</header>

CodePudding user response:

Just add this into your code :

header{
position: relative;
}

.logo{
 position: absolute;
 top: 0px;
 left: 0px;
}

See this example:-

@import url('https://fonts.googleapis.com/css2?family=Montserrat Alternates:ital,wght@0,500;1,400&display=swap')

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  background-color: #F5F5F5;
}

li,
a,
button {
  font-family: "Montserrat", sans-serif;
  font-weight: 500;
  font-size: 16px;
  color: #000000;
  text-decoration: none;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px 10%;
  background: linear-gradient(rgba(165, 246, 144, 0.3) 0%, rgba(158, 249, 216, 0.63) 100%);
  height: 56px;
  position: relative;
}

p {
  position: absolute;
  width: 584px;
  height: 67px;
  left: 232px;
  top: 25px;
  text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
  background: url(pharmapp.png);
  align-items: center;
  font-family: 'Montserrat';
  font-style: italic;
  font-weight: 400;
  font-size: 16px;
  line-height: 34px;
  color: #000000;
}
.logo {
    /* position: relative; */
    /* float: left; */
    margin-block-start: 10px;
     background: url(pharmapp.png); 
    height: 122px;
    /* left: 20px;
    top: 0px; */
    position: absolute;
    top: 0px;
    left: 0px;
    bottom: 40px;
  }
  
<header >
  <div>
    <img  src="img/pharmapp.png" alt="logo">
    <p >Medicines on your Doorstep</p>
  </div>
  <nav >
    <ul>
      <li><a href="#">Login</a></li>
      <li><a href="#">SignUp</a></li>
      <li><a href="#">About</a></li>
    </ul>
  </nav>
  <a  href="#"><button>Contact</button></a>
</header>

  •  Tags:  
  • css
  • Related