为什么我的背景颜色不显示如果我有显示:内联? [英] Why is my background color not showing if I have display: inline?

查看:204
本文介绍了为什么我的背景颜色不显示如果我有显示:内联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
    <body>
       <div style="display: inline; background-color: #555;">
            <h3>test</h3>
       </div>
    </body>
</html>

这是我的代码。我想知道为什么我的背景颜色不显示。如果我将css显示从inline更改为block,则会显示。如果显示为内联,为什么它不显示? 我想尝试解决问题的原因,而不是寻找解决方案。

Here is my code. I am wondering why my background color isn't showing. If I change css display from inline to block, then it show up. Why is it not showing up if display is inline? I am trying to understand the reason of the problem other than looking for a solution.

推荐答案

div不占用空间,如果它是内联。如果你想要一个内联元素显示为孩子的身高,然后使用 display:inline-block;

The div doesn't take up space if it's inline. if you want an inline element that shows as the children's height, then use display: inline-block;.

至于好的讨论,我相信 QuirksMode 比我自己的好。要点是 inline 元素不会推动其他元素。

As for a good discussion, I'd trust QuirksMode's take better than my own. The gist is that an inline element doesn't push other elements out of the way.

这篇关于为什么我的背景颜色不显示如果我有显示:内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆