【问题标题】:Is there a way to prevent background of a parent element from showing up on the edge when both parent and child have a border radius?当父元素和子元素都具有边框半径时,有没有办法防止父元素的背景出现在边缘?
【发布时间】:2016-02-20 01:28:15
【问题描述】:

假设我们在另一个 div 中有一个 div;父 div 和子 div 都具有相同的边框半径,并且子 div 的宽度和高度是父 div 的 100%。如果父项的背景与子项的背景不同,则该背景的细线将在子项的圆角周围可见:

这就是它的样子:

以下是 CodePen 上的示例:http://codepen.io/azangru/pen/MKdQmG

还有代码本身:

HTML:

<div class="dark-bg">
  <div class="outer">
    <div class="middle">
      <div class="inner">
      </div>
    </div>
  </div>
</div>

CSS:

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

.dark-bg {
  height: 100%;
  width: 100%;
  padding-top: 10px;
  background: black;
}

.outer {
  width: 200px;
  height: 200px;
  margin: auto;
  background: white;
  border-radius: 10px;
}

.middle {
  width: 100%;
  height: 100%;
  background: yellow;
  border-radius: 10px;
}

.inner {
  width: 100%;
  height: 100%;
  background: black;
  border-radius: 10px;
}

有没有办法防止父母的背景从孩子身后出现(我的意思是不完全移除父母的背景)?

【问题讨论】:

  • 预期输出是什么?
  • 我只想让孩子的背景完全隐藏父母的背景。

标签: css


【解决方案1】:

试试这个:

  .inner {
     border-radius: 8px;
  }

为什么? http://www.mrgeek.me/technology/tutorials/web-design/css3-border-radius-property-explained/

看看它的工作原理:

http://codepen.io/anon/pen/RrmQeG

【讨论】:

  • 它适用于测试示例,所以我想这是一个正确的答案,但它并没有解决我在我正在处理的代码库中看到的问题。我有一种不好的感觉,如果孩子也有背景,我实际上将不得不求助于 JavaScript 来删除父母的背景:-(
  • 好的,我的部分问题还在于我有溢出:隐藏在我的工作代码中的父元素上:-) 现在这个属性已经消失了,你的解决方案可以完美运行!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-20
  • 2014-02-24
  • 1970-01-01
  • 2015-02-24
  • 1970-01-01
  • 2015-08-30
相关资源
最近更新 更多