Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center logo in html

I have an logo in the header of the page and I want to make in centered. This is my html:

body {
  width: 90%;
  margin: 0 auto;
}
header {
  margin-top: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #b5b5b5;
}
.logo {
  width: 250px;
  height: 150px;
  text-align: center;
}
<body>
  <header>
    <div class="row">
      <div class="logo-row">
        <img src="resources/img/logo.png" alt="logo" class="logo">
      </div>
    </div>
  </header>
like image 533
Lila Avatar asked Feb 02 '16 19:02

Lila


People also ask

How do I center align a logo in CSS?

To center an image, we have to set the value of margin-left and margin-right to auto and make it a block element by using the display: block; property. If the image is in the div element, then we can use the text-align: center; property for aligning the image to center in the div.

How do I center something in HTML?

One way to center text or put it in the middle of the page is to enclose it within <center></center> tags. Inserting this text within HTML code would yield the following result: Center this text!

How do I center a PNG in HTML?

Using the <center> tag You can center a picture by enclosing the <img> tag in the <center></center> tags. This action centers that, and only that, picture on the web page.

How do I align an image in HTML?

We use <img> align attribute to align the image. It is an inline element. Attribute Values: left: It is used for the alignment of image to the left.


2 Answers

You need to add a width to the logo-row class and use margin: 0 auto.

body {
    width: 90%;
    margin: 0 auto;
}

header {
    margin-top: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #b5b5b5;
}

.logo-row {
    width: 250px;
    margin: 0 auto;
}

.logo {
    width: 100%;
    height: 150px;
    text-align: center;
}
<body>
  <header>
    <div class="row">
      <div class="logo-row">
        <img src="resources/img/logo.png" alt="logo" class="logo">
      </div>
    </div>
  </header>
like image 81
Richard Hamilton Avatar answered Sep 28 '22 09:09

Richard Hamilton


Giving text-align: center to the .logo-row, you may achieve the desired output:

header {
  margin-top: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #b5b5b5;
}
.logo-row{
  text-align: center;
}
.logo {
  width: 250px;
  height: 150px;
  text-align: center;
}
  <header>
    <div class="row">
      <div class="logo-row">
        <img src="resources/img/logo.png" alt="logo" class="logo">
      </div>
    </div>
  </header>
like image 21
Pmpr.ir Avatar answered Sep 28 '22 08:09

Pmpr.ir