I am trying to center my logo in my header on screens with a width under 901px
using media queries. I used left: 50%
and translate: transformX(-50%)
and it does change the position of the logo from the left of the header to off-center. I want it to be dead on center and I don't understand why it doesn't work.
#bars {
display: none;
}
header {
display: flex;
flex-direction: row;
align-items: center;
padding-top: 7px;
padding-bottom: 7px;
height: 26px;
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 10;
}
#logo {
width: 12%;
margin-left: 3%;
}
#pin {
margin-right: 3%;
width: 2%;
margin-left: auto;
}
nav a {
margin-left: 20px;
margin-right: 20px;
}
nav {
margin: auto;
}
@media screen and (max-width: 900px) {
nav a {
display: none;
}
nav {
display: none;
}
#bars {
display: block;
color: white;
margin-left: 3%;
}
header #logo {
margin-left: 0;
left: 50%;
position: relative;
transform: translateX(-50%);
width: 15%;
}
}
<header>
<i class="fa-solid fa-bars" id="bars"></i>
<img src="logo.svg" id="logo">
<nav>
<a href="index.html">Accueil</a>
<a href="nosproduits.html">Nos produits</a>
<a href="apropos.html">À propos</a>
<a href="contact.html">Contact</a>
</nav>
<a id="pin" href="#"><img src="pin.svg"> </a>
</header>