在不固定任何元素的宽度的情况下,我希望父 div 元素在设置宽度时忽略文本。我希望元素的宽度仅受图像宽度的影响。
<div>
<img src="https://lh4.ggpht.com/9BAW9uE48gxNUmnQ7T6ALpNTsrCHOZBMfF__mbamBC36edSw0uc-kjQxgtZ3O3aQWFY=h900"/>
<p>I want this text to wrap once this paragraph element reaches the width of the image.</p>
</div>
div {
background: green;
display: inline-block;
}
非常感谢任何建议
最佳答案
改变div的显示属性为table-caption
(在 firefox 和 chrome 中测试)
已更新 jsfiddle
关于html - CSS 父元素忽略子元素内的文本来确定宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17955113/