html - 什么时候子元素会影响父元素的位置?

标签 html css

我放了一个<img>元素变成 <div>元素。我想 <img>只是在那里,但它改变了 <div> 的位置元素。

我的 HTML 的简化结构:

<div class="box" id="box6">
<img src="circle-shape-outline.svg">

</div>

还有 CSS:

div.box {
    display: inline-block;
    margin: 0px;
    border: 2px solid #364F6B;
    border-top: none;
    border-left: none;

    width: 32.9%;
    height: 33%;
 }

div#box6 {
    border-right: none;
}

截图:

enter image description here

我该如何解决?您可以在 codePen 上查看完整代码谢谢

最佳答案

你的 <div>我们有display: inline-block所以当你添加 <img>它会尝试将图像调整到当前行的底部。

可以设置float: left在图像或集合上position: relative#box6然后 position: absolute<img>放置在 div 中您想要的任何位置。

关于html - 什么时候子元素会影响父元素的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37495839/

相关文章:

javascript - 将线性渐变与动态背景图像相结合

html - 防止标题下的 float UL 和 LI 元素

css - 在 Windows 上配置 compass

css - 为什么位置设置为固定的部分与其他部分一起移动?

html - 如何将页面扩展到全屏

php - 在不提交的情况下保存和加载表单中的数据

html - 如何将水平线延伸到页面容器的边缘?

html - 您可以在不链接到外部源的情况下在 HTML 中嵌入字体吗?

html - @font-face 函数不起作用

javascript - 无法在 IE8 上获取标签的 innerHTML