简体   繁体   中英

How to vertically align a rotated image caption?

I am trying to align an image caption on the bottom left side of an image container.

Here is a picture of the desired outcome.

在此处输入图像描述

This is the HTML/CSS I am working with:

 .elementor-image figure { position: relative; }.elementor-image figure figcaption { position: absolute; bottom: 0; left: -40px; transform: rotate(-90deg); }
 <div class="elementor-image"> <figure class="wp-caption"> <img src="https://picsum.photos/200/300"> <figcaption class="widget-image-caption wp-caption-text">The Lorem <span></span></figcaption> </figure> </div>

There are two problems with my code:

  1. The rotated text does not start from the bottom left-hand corner.
  2. Applying left: -40px doesn't always align the text with the image (sometimes it overlaps on top of the image).

Here is another screenshot illustrating the problem.

在此处输入图像描述

I hope I have explained myself correctly, I have been banging my head with this, so I would really appreciate your input and thoughts. Thanks!

Simply consider transform-origin:bottom left;

 .elementor-image figure { position: relative; }.elementor-image figure figcaption { position: absolute; bottom: 0; left: 0; transform: rotate(-90deg); transform-origin:bottom left; } img { display:block; /* to avoid white space and have a perfect alignment */ }
 <div class="elementor-image"> <figure class="wp-caption"> <img src="https://picsum.photos/200/300"> <figcaption class="widget-image-caption wp-caption-text">The Lorem <span></span></figcaption> </figure> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM