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

Image Grid formatting in HTML

I am a beginner in HTML and StackOverflow and was trying to create a web page. I learned how to create this grid through some research but I am not sure how I would align it to the center of the web page. I tried using justify-content: center; but had no luck. Help would be greatly appreciated.

The actual web page

The CSS code:

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

.image-grid {
  --gap: 16px 16px;
  --num-cols: 4;
  --row-height: 40px;

  padding: var(--gap);

  display: grid;
  grid-template-columns: repeat(var(--num-cols), 1fr);
  grid-auto-rows: car(--row-height);
  gap: var(--gap);
}

img {
  border-radius: 15px;
  border: 5px solid;
}

.container {
  position: relative;
  width: 50%;
}

.image {
  display: block;
  width: 150px;
  height: 150px;
}

.overlay {
  position: absolute;
  top: 5px;
  bottom: 0;
  left: 5px;
  right: 0;
  height: 150px;
  width: 150px;
  opacity: 0;
  transition: 0.5s ease;
  border-radius: 10px;
  background-color: rgb(149, 69, 53);
}

.container:hover .overlay {
  opacity: 1;
}

.text {
  color: black;
  font-family: "Courier New", Courier, monospace;
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

The Html code (I have 16 pictures in my grid so the is basically repeated 16 times):

<div class="image-grid">
    <div class="container">
      <img
        src="picture"
        alt="Avatar"
        class="image"
      />
      <div class="overlay">
        <div class="text">Angelite<br /><br />STONE OF AWARENESS</div>
      </div>
    </div>
<div>

>Solution :

You meant this?
.image-grid {place-items: center;}

By the way pay attention to your last line! Don’t forget to close the tag!

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