使用float,我可以将文本包裹在figure标记中,而不是包裹在figcaption标记中。将float添加到figcaption不会这样做。有什么建议吗?

下面的代码在这里:https://jsfiddle.net/ujb6bwjq/

<html><head><style>
body { width: 200px; }
figure {
       width: 100px;height: 100px;padding: 0px;margin: 10px;
       float:left;
       }
figcaption { font-size: 9pt; }
</style></head>
<body>
       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem.</p>
       <figure>
                <svg width="100px" height="100px"><polygon points="0,0 100,0 100,100 0,0" /></svg>
                <figcaption>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem.</figcaption>
       </figure>
       <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem.</p>
</body></html>


相关但对我没有帮助:HTML5 wrap text around image with caption

最佳答案

花了我一段时间才能理解您的意思,但最简单的解决方案是李斯特先生所说的:从height CSS选择器中删除figure属性:



body {
    width: 200px;
}
figure {
    width: 100px;
    padding: 0px;
    margin: 10px;
    float: left;
}
figcaption {
    font-size: 9pt;
}

<body>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem.</p>
    <figure>
        <svg width="100px" height="100px">
            <polygon points="0,0 100,0 100,100 0,0" />
        </svg>
        <figcaption>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem.</figcaption>
    </figure>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at ante. Mauris eleifend, quam a vulputate dictum, massa quam dapibus leo, eget vulputate orci purus ut lorem.</p>
</body>





如果必须将显式height: 100px;保留在其中,则添加display: table;会得到相同的结果。

关于css - 如何在figcaption周围换行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41129268/

10-13 08:59