Image caption width to same as image

前端 未结 6 743
生来不讨喜
生来不讨喜 2020-12-25 13:16

How can I make image caption width same as image? Now I have the following code:

\"\" &
6条回答
  •  失恋的感觉
    2020-12-25 13:58

    You can apply display:table; and an arbitrary initial width, eg. width:7px; to the parent block like figure and everything will work as expected!

    Here is a live demo: http://jsfiddle.net/blaker/8snwd/

    This solution's limitation is that IE 7 and earlier do not support display:table; and IE 8 requires your doctype to be !DOCTYPE.

    Sources:

    • http://www.lifeathighroad.com/web-development/forcing-to-wraps-to-the-width-of-an-image-using-css-only/
    • W3Schools (can't post link due to stackoverflow's 2-link limit for people with less than 10 rep)

提交回复
热议问题