【问题标题】:Why does CSS border background color inherit content background color? [duplicate]为什么 CSS 边框背景颜色会继承内容背景颜色? [复制]
【发布时间】:2021-04-22 20:59:40
【问题描述】:

我正在学习 CSS 中的框模型,我很困惑为什么应用点边框时边框会继承内容背景颜色的颜色?

在下面的 sn-p 中,虚线边框不应该是黑色和浅蓝色的颜色组合,因为盒子模型建议边框围绕填充和内容?而是显示橙色和黑色。

我很难理解内容背景颜色的显示方式? 如果我的解释令人困惑,我们深表歉意,但我们将不胜感激。

body {

    background-color: lightblue;
}

.content {

  background-color: #fdad5c;
  padding:0px;
  border: 5px dotted black;
  margin: 0px;


}
<body>

<div class = 'content'> Content  </div>

</body>

【问题讨论】:

  • 阅读背景剪辑

标签: html css flexbox frontend border


【解决方案1】:

我知道你的意思。但是 CSS 中的边框总是使用元素所在的空间。这就是为什么在您的示例中,虚线位于黄色框“内部”而不是外部。

边框的替代方法是outline 属性,在您的示例中,该属性位于黄色框之外。

更多信息: https://www.tutorialrepublic.com/css-tutorial/css-outline.php

【讨论】:

    猜你喜欢
    • 2020-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 2020-03-15
    • 2014-08-09
    • 2017-11-01
    • 1970-01-01
    相关资源
    最近更新 更多