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

How to center a h1 tag inside a section tag

I need to center-left a < h1 > element inside a < section >, however, I’m struggling finding the correct method.

I’ve tried using justify-content and text-align, but it doesn’t move it. I can move with it padding, but, I’m not sure this is good responsively.

HTML:

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

<section class="hero">
  <h1 class="hero__title">My Website</h1>
  <img
    class="hero__image"
    src="./assets/images/hero-bio.jpg"
    alt="hero-image"
  />
</section>

SCSS:

    .hero {
  width: 100%;
  height: 700px;
  position: relative;

  &__image {
    height: 100%;
    width: 100%;
    object-fit: cover;
  }

  &__title {
    color: white;
    font-size: 6rem;
    position: absolute;
  }
}

>Solution :

Using top: 50% would work in your current situation.

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