Image won't resize

I’m working on this really simple project where I am trying to create a mock website for a story I brainstormed a couple years ago, but I’m having issues with the image as it won’t resize no matter what I do.

Here is the HTML code:

  <div class="header-img">
    <img src="" alt="cat with butterfly on nose">

and here is the CSS code:

.img-header {
  max-width: 1024px;
  height: 768px;
  object-fit: contain;

I would appreciate the help. I know it’s something probably very simple, but for the life of me, I can’t figure it out. Any guidance is appreciated. Thank you.

P.S. I forgot to add that I had initially started with img first before adding .img-header and it didn’t work.

Your class is called header-img, not img-header.
Also, you need to style the image, not the container: .header-img img.
And add a width: 100%;


Sidebar comment (opinion)… If it’s a header background image, then it really is only window dressing; why not use a CSS background, instead of an img tag? Who wants their header image to be indexed by search engines? Nobody I know.

Only indexable images, for the most part, should be written into IMG elements, with appropriate FIGURE and FIGCAPTION markup and alternate text. Everything else belongs to the skin graphics category, and is in the domain of CSS.


Thank you so much for pointing that out!

1 Like