javascript - How to make an image height resize accordingly to the size of the contents below it, in a fixed size container -


i understand hard one, have 10+ years working html, can't find solution doesn't involve working complicated calculations javascript.

i have fixed-size container divided in two, container has top half , bottom half. top half has image. bottom half has text. want image , text occupy available space. if text short, there more space available image. if text larger, image smaller, dynamically. i've added couple of screenshots illustrate want. in cases, occupy 100% of available vertical space of fixed-size container.

image 1 line of text below it

image multiple lines of text below it

here's pure css approach

you can try using display: table-row

https://jsfiddle.net/4h37fv7o/

try , modify length of text @ bottom , see image resize.

there caveats works.

alternatively, can use flexbox albeit, using background image:

https://jsfiddle.net/kdm0amsx/1/


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -