0

I tried everything including display block and margin auto and flexbox justify-content: center; but nothing seems to work.. I am new to css so if you're wiling to help you will mot probably find a minimal error that no one else does that changes everything.

.container {
    width: 1024px;
    min-height: 1000px;
    background-color: red;
    margin: 10px auto;
}

header {
    width: 100%;
    height: 150px;
    background-color: black;
}

.logo {
    margin: auto;
}
<body>
    <div class="container">
        <header>
            <div class="logo">
                <a href="index.html">
                    <img src="images/Logo-lowres.svg" alt="">
                </a>
            </div>
        </header>
    </div>
</body>
DaFois
  • 2,197
  • 8
  • 26
  • 43
samervjr
  • 29
  • 5

2 Answers2

2

.container {
  width: 1024px;
  min-height: 1000px;
  background-color: red;
  margin: 10px auto;
}

header {
  width: 100%;
  height: 150px;
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
}
<body>
  <div class="container">
    <header>
        <a href="index.html">
          <img src="https://via.placeholder.com/100" alt="">
        </a>
    </header>
  </div>
</body>

Add

display: flex;
justify-content: center;
align-items: center;

to your header and remove the margin from the .logo div. I don't know if you really need the .logo div, otherwise you can remove it.

Andris Jefimovs
  • 689
  • 6
  • 17
1

HEre you go

.container {
    width: 1024px;
    min-height: 1000px;
    background-color: red;
    margin: 10px auto;
}

header {
    width: 100%;
    height: 150px;
    background-color: black;
}

.logo {
    margin: auto
       display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: row;
    -ms-flex-direction: row;
    flex-direction: row;
    -webkit-flex-wrap: nowrap;
    -ms-flex-wrap: nowrap;
    flex-wrap: nowrap;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-align-content: stretch;
    -ms-flex-line-pack: stretch;
    align-content: stretch;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
}

img {
  border-radius: 50%;
}
<div class="container">
        <header>
            <div class="logo">
                <a href="index.html">
                    <img src="https://i.picsum.photos/id/557/200/200.jpg?hmac=Y3oVAxcM0NGQ6OBLGhCOaRI9_TBDXdJFB8547MBovxU" alt="">
                </a>
            </div>
        </header>
    </div>

Basically, you can either apply margin 10px auto and display block to the image element or do like in the snippet, use flexbox on the parent element.

ptts
  • 1,022
  • 8
  • 18