Html 如何将div环绕在图像上?

Html 如何将div环绕在图像上?,html,css,word-wrap,Html,Css,Word Wrap,我试图将图像包装到一个div中,但该div被父div扩展 <div id="parent" style="display: inline-block; position: relative; text-align:center"> <div id="wrapper"> <img> </div> <p>Some text that expands the wrapper div more than

我试图将图像包装到一个div中,但该div被父div扩展

<div id="parent" style="display: inline-block; position: relative; text-align:center">
    <div id="wrapper">
        <img>
    </div>
    <p>Some text that expands the wrapper div more than image width</p>
</div>

某些文本扩展包装器div超过图像宽度

文本字段将父div扩展为比图像宽,这也将扩展包装div。如何使包装div与img的大小完全相同


img和包装都没有边距或填充,但包装div比图像宽。

在#包装器上使用
display:inline block


在包装器上使用
显示:内联块


在包装器上使用
显示:内联块


在包装器上使用
显示:内联块


您需要在wraper元素上设置
显示:内联块

 <div id="parent" style="display: inline-block; position: relative; text-align:center">
    <div id="wrapper" style="display: inline-block;">
        <img src="https://cdn2.iconfinder.com/data/icons/picol-vector/32/source_code-128.png" />        
    </div>    
    <p>Some text that expands the wrapper div more than image width</p>
</div>

您需要在wraper元素上设置
显示:内联块

 <div id="parent" style="display: inline-block; position: relative; text-align:center">
    <div id="wrapper" style="display: inline-block;">
        <img src="https://cdn2.iconfinder.com/data/icons/picol-vector/32/source_code-128.png" />        
    </div>    
    <p>Some text that expands the wrapper div more than image width</p>
</div>

您需要在wraper元素上设置
显示:内联块

 <div id="parent" style="display: inline-block; position: relative; text-align:center">
    <div id="wrapper" style="display: inline-block;">
        <img src="https://cdn2.iconfinder.com/data/icons/picol-vector/32/source_code-128.png" />        
    </div>    
    <p>Some text that expands the wrapper div more than image width</p>
</div>

您需要在wraper元素上设置
显示:内联块

 <div id="parent" style="display: inline-block; position: relative; text-align:center">
    <div id="wrapper" style="display: inline-block;">
        <img src="https://cdn2.iconfinder.com/data/icons/picol-vector/32/source_code-128.png" />        
    </div>    
    <p>Some text that expands the wrapper div more than image width</p>
</div>


您还有其他css吗?
div
s是块元素,因此它们将占据其父元素的全部宽度。尝试将
wrapper
设置为
display:inline
float:left
,具体取决于您希望它的显示方式。@Firze将display:inline块放在#wrapper上。您还有其他css吗?
div
是块元素,因此它们将占据其父元素的全部宽度。尝试将
wrapper
设置为
display:inline
float:left
,具体取决于您希望它的显示方式。@Firze将display:inline块放在#wrapper上。您还有其他css吗?
div
是块元素,因此它们将占据其父元素的全部宽度。尝试将
wrapper
设置为
display:inline
float:left
,具体取决于您希望它的显示方式。@Firze将display:inline块放在#wrapper上。您还有其他css吗?
div
是块元素,因此它们将占据其父元素的全部宽度。尝试将
wrapper
设置为
display:inline
float:left
,具体取决于您希望它的显示方式。@Firze将display:inline块放在#wrapper.Oh上。我很确定我已经试过了,但显然我没有。谢谢我现在觉得自己很笨。@Firze我喜欢给元素添加边框,这样我就能准确地看到发生了什么。希望你能试试我的方法。:)如果
display:inline块
不起作用,请尝试使用
display:inline
。哦。我很确定我已经试过了,但显然我没有。谢谢我现在觉得自己很笨。@Firze我喜欢给元素添加边框,这样我就能准确地看到发生了什么。希望你能试试我的方法。:)如果
display:inline块
不起作用,请尝试使用
display:inline
。哦。我很确定我已经试过了,但显然我没有。谢谢我现在觉得自己很笨。@Firze我喜欢给元素添加边框,这样我就能准确地看到发生了什么。希望你能试试我的方法。:)如果
display:inline块
不起作用,请尝试使用
display:inline
。哦。我很确定我已经试过了,但显然我没有。谢谢我现在觉得自己很笨。@Firze我喜欢给元素添加边框,这样我就能准确地看到发生了什么。希望你能试试我的方法。:)如果
display:inline块
不起作用,请尝试使用
display:inline