masakudamatsu / template

Template code for making a website
MIT License
1 stars 0 forks source link

Keep the scaling image vertically center-aligned #20

Closed masakudamatsu closed 5 years ago

masakudamatsu commented 5 years ago

By default, the scaling image is top-aligned. This may not be useful if the meat of the image is located around the center.

A StackOverflow discussion on vertically center-aligning an image gives a nice solution, with the use of relatively absolute positioning (cf. Interneting Is Hard's tutorial on absolute positioning).

.figure__frame {
  position: relative;
}

.figure__image {
  margin: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

By changing the values for the top/bottom/left/right properties, we can fine-tune the positioning of a scaling image.