html - CSS 父元素忽略子元素内的文本来确定宽度

标签 html css

在不固定任何元素的宽度的情况下,我希望父 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;
}

my jsFiddle

非常感谢任何建议

最佳答案

改变div的显示属性为table-caption
(在 firefox 和 chrome 中测试)

已更新 jsfiddle

关于html - CSS 父元素忽略子元素内的文本来确定宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17955113/

相关文章:

html - 在 IE 中填充文本输入...可能吗?

CSS Grid : grid-column with span, calc() 和 CSS 变量在 WebKit 浏览器中不起作用

html - Float 在某些元素的 CSS 上无法正常工作

html - 单击链接时纯 HTML/CSS 下拉菜单关闭(链接不打开)

javascript - 我们什么时候赋值调用jQuery事件?

php - Uncaught ReferenceError : getWidget is not defined

html - 在 CSS 中定位背景图像

javascript - 我想根据我的过滤器更新面包屑

html - 如何使用 jquerymobile 制作粘性页脚?

css - 为什么这个 div 的位置是 :absolute taking all remaining width?