How do I align two different pieces of text in a box? I would like Header to be on Top, and Description to be in middle. See below. Align Self-center moves description in the middle, however trying to make Header on top regardless of box size.
Goal to keep description static in middle, regardless of title overflow.
.grid-container { display: grid; grid-template-columns: 140px 140px; grid-template-rows: 140px; align-items: stretch; } img { width: 100%; height: auto; } .test { text-align:center; vertical-align:center; align-self: center }
<div class="grid-container" id="gridid42f08d611e2346748fbe47264fd732e0"> <img class="imgcard mCS_img_loaded" id="imgid42f08d611e2346748fbe47264fd732e00" src="https://www.woodlandtrust.org.uk/media/100078482/Sycamore01.jpg?cb=-11897985&preset=gallery-tab-main-image"> <div class="test"> Header <br> Description </div> </div>
Goal:
test
You can use flex box to organize your element and align theme accordingly
See code snippet:
.grid-container { display: grid; grid-template-columns: 140px 140px; grid-template-rows: 140px; align-items: stretch; } img { width: 100%; height: auto; } .test { display: flex; flex-direction: column; align-items: center; } .description { flex-grow: 1; display: flex; align-items: center; }
<div class="grid-container" id="gridid42f08d611e2346748fbe47264fd732e0"> <img class="imgcard mCS_img_loaded" id="imgid42f08d611e2346748fbe47264fd732e00" src="https://www.woodlandtrust.org.uk/media/100078482/Sycamore01.jpg?cb=-11897985&preset=gallery-tab-main-image"> <div class="test"> <div class="header">Header</div> <div class="description"> Description</div> </div> </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.