【问题标题】:<figure>&<figcaption> with floating image, figcaption wraps, and article text wraps around image/caption<figure>&<figcaption> 带有浮动图像,figcaption 环绕,文章文本环绕图像/标题
【发布时间】:2013-07-15 07:11:25
【问题描述】:

在网上搜索了数周,但找不到满足我所有需求的答案(仅部分),非常欢迎帮助。

我想要并且已经完成的:

  • 纯 HTML5 兼容和 CSS
  • 在文章中显示图片
  • 图片必须有标题
  • 标题必须在图片下方
  • 标题必须限制为图像的水平尺寸
  • 标题可能超过一行,文本应换行到下一行(仍在图片大小范围内)
  • 图像和标题必须作为一组向左或向右浮动(考虑使用&lt;figure class="left"&gt;
  • 文章的文字必须环绕图片和标题
  • 图片大小不同(第一张图片是 200 像素,第二张图片是 320 像素等)

现在我想添加这些要求:

  • 我不喜欢像&lt;figure class="left" style="width:200px"&gt;那样添加图像的原始宽度,但前提是没有其他方法。
  • 响应式设计:当图像宽度将占显示宽度的 50% 以上时,必须限制在显示宽度的 50% 以内。
  • 当显示宽度为 320px 或以下时,图片不能浮动,但必须是块级元素,所以图片周围没有文字环绕。

我离开的地方:

figure {
  display: inline
}

figcaption {
  display: block
}

figure.left {
  float: left
}

figure.right {
  float: right
}
<p>This is a part of the text of the article and at this point a image is inserted at the left side
  <figure class="left" style="width:250px">
    <img src="image.png" alt="img txt">
    <figcaption>image caption and a lot of text</figcaption>
  </figure>
  and the article text goes on and on so that it will wrap around the image</p>

(我省略了填充/边距等以使其看起来更好。)

【问题讨论】:

    标签: css html figure


    【解决方案1】:

    试试下面的css,看看当你调整浏览器大小时,图片上的文字会换行:

    .left {
      float: left;
      border: 5px solid #BDBDBD;
      background: #E0E0E0;
      padding: 5px;
      margin: 0px;
    }
    
    figcaption {
      text-align: center;
    }
    

    【讨论】:

      【解决方案2】:

      也许这对你来说感觉太 html3,但我找到了这个答案:

      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;
      }
      

      我不认为 HTML5 或 CSS3 禁止这样做,而且它似乎对我有用。

      撇开响应式设计要求不谈 - 我觉得这是一个单独的问题,我没有一个好的纯 CSS 答案。

      【讨论】:

        【解决方案3】:

        这可能会帮助某人解决它。我也在寻找一种在图像右侧显示与图像高度相同的标题的方法。

        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>

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-05-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-12-18
          • 2022-06-29
          相关资源
          最近更新 更多