我在另一个div中有一个div.#outer#inner.#outer具有弯曲的边框和白色背景.#inner没有弯曲的边框和绿色背景.#inner超出了#outer的曲线边界.有什么办法可以阻止这一切吗?

#outer {
  display: block;
  float: right;
  margin: 0;
  width: 200px;
  background-color: white;
  overflow: hidden;
  -moz-border-radius: 10px;
  -khtml-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
}

#inner {
  background-color: #209400;
  height: 10px;
  border-top: none;
}
<div id="outer">
  <div id="inner"></div>
  <!-- other stuff needs a white background -->
  <!-- bottom corners needs a white background -->
</div>

无论我如何try ,它仍然重叠.我怎样才能让#inner服从并填满#outer的边界?

edit

下面的黑客攻击暂时达到了目的.但问题是(可能对CSS3和webbrowser的作者来说):Why don't child elements obey their parent's curved borders and is there anyway to force them to?

目前,为了满足我的需要,绕过这一问题的方法是,您可以将曲线指定给各个边界.因此,出于我的目的,我只是给内部元素的前两个元素指定了一条曲线.

#inner {
    border-top-right-radius: 10px; -moz-border-radius-topright: 10px; -webkit-border-top-right-radius: 10px;
    border-top-left-radius: 10px; -moz-border-radius-topleft: 10px; -webkit-border-top-left-radius: 10px;
}

推荐答案

根据规格:

框的背景,但不是其 边框图像,被剪裁到 适当的曲线(由 ‘Background-Clip’).其他效果 剪裁到边框或填充边缘 (如‘溢出’,而不是 ‘Visible’)还必须剪辑到 曲线.The content of replaced elements is always trimmed to the content edge curve.还有,这个地区 在边界边的曲线之外 不代表接受鼠标事件 元素的.

http://www.w3.org/TR/css3-background/#the-border-radius

这意味着#outer上的overflow: hidden应该可以工作.然而,这不适用于Firefox3.6及更低版本.这在Firefox 4中已修复:

圆角现在剪辑内容和图像(如果未设置溢出:可见).

https://developer.mozilla.org/en/CSS/-moz-border-radius

因此,您仍然需要修复,只需将其缩短为:

#outer {
  overflow: hidden;
}

#inner {
  -moz-border-radius: 10px 10px 0 0;
}

See it working here: 100

Css相关问答推荐

主dart 文件未加载Flutter Web

如何仅以WooCommerce单一产品页面为目标?

Safari CSS扫描动画效果不起作用

CSS媒体查询不显示所需的输出

具有不同边框宽度和 colored颜色 的边框半径,Safari渲染问题

Next.js中的TailWind CSS类名称疑难解答

如何使用 :has() 父 Select 器 Select 父元素的子元素,在父元素和子元素之间没有中间层的情况下?

有没有办法在 CSS 字体速记中使用数字字体粗细?

TypeScript 中有效的 CSS 属性名称数组,但带有连字符

Flex & space-around 与内容相交

Nativewind 的某些样式不适用于本机 (Android),但它们适用于网络

没有 colored颜色 Select 器的 JavaFX colored颜色 Select 器

Angular (13) material - 覆盖 CSS 文件不起作用

卡在 CSS 中的grid-template-columns中

在 CSS 中相对于另一个元素定位一个元素

悬停时如何在图像上显示文字?

如何更改 Angular Material 上 mat-icon 的大小?

内联块列表项中不需要的边距

使用 :focus 设置外部 div 的样式?

CSS:悬停一个元素,多个元素的效果?