<figure>&<figcaption> with floating image, figcaption wraps, and article text wraps around image/caption

泪湿孤枕 提交于 2019-12-05 18:33:13
SRL

Try the following css and look when you resize the browser, the text wrap on the image:

.left {
  float: left;
  border: 5px solid #BDBDBD;
  background: #E0E0E0;
  padding: 5px;
  margin: 0px;
}

figcaption {
  text-align: center;
}

Maybe this feels too html3 to you, but I found this answer:

http://www.sitepoint.com/forums/showthread.php?1049396-How-to-force-this-figcaption-element-to-respect-its-parent-s-width-boundaries

figure {
  display: table;
}
figcaption {
  display: table-caption;
  caption-side: bottom;
}

I don't think this is forbidden by HTML5 or CSS3 and it certainly seems to work for me.

Leaving aside the responsive design requirements - I feel like that's a separate question to which I don't have a good CSS-only answer.

Võ Minh

This may help someone solve it. I am also looking for a way to display the caption on the right of the image with the same height as the image.

figure, .figure {
  
     display: inline-table;
}

figcaption {
    display: table-caption;
     caption-side: bottom;
      background-color: red;
  
}
     
img {
     width: 100%;
}
     
.image {
     width: auto;
}
     
     figure div {
          display: inline-table;
          background-color: aqua;
     }
     
.caption {
    display: table-caption;
     caption-side: top;
      background-color: red;
     margin: 0;
}
<figure>
    <h2 class="caption">caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption </h2>
    
        <img src="http://mintnet.net/images/thumbs/small-mossy.jpg"> 
        <figcaption>caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption </figcaption>
</figure>

<figure>
    <figcaption>caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption </figcaption>
    
        <img src="http://mintnet.net/images/thumbs/small-mossy.jpg">
       
</figure>

<figure>
    <div class="caption">caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption caption </div>
    
       <div><img  class="image" src="http://mintnet.net/images/thumbs/small-mossy.jpg">
            </div> 
       
</figure>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!