javascript - 当宽度为 2% 时,子 div 重叠圆形(带半径)容器

标签 javascript jquery html css

我有一个带有半径的长方形容器。

容器中还有 3 个子 div。

这里是:

normal

如上图所示,第一个子容器(白色)和第三个(红色)也设置了半径以匹配容器半径。

现在,子容器的宽度将是动态的(可由用户更改)。因此,用户将能够更改所有三个子容器的宽度以满足他们的需要。

但是看看当我将第三个容器的宽度设置为 2% 时会发生什么:

with 2% width

当我对第一个 child 做同样的事情时,同样的事情发生了(它与容器的圆形边框重叠)。

子容器 1(白色)向左浮动,子容器 3(红色)向右浮动。

我需要一种方法来阻止重叠的发生。

我可以使用 JS 和 JQuery,以防你疑惑。

谢谢

编辑: CSS:

.parent {
    border: 1px solid #5B5B5B;
    height: 30px;
    width: 80%;
    right: 0%;
    position: relative;
    margin-right: auto;
    margin-left: auto;
    <? set_radius("25px",true);
    set_box_shadow("1px","1px","#F8F8F8");?>    
    overflow: hidden;
    z-index: 3;
}
    .child_class {
        display: inline-block;
        position: relative;
        width: auto;
        height: 100%;
        margin: 0px;
        border-right-width: 1px;
        border-right-style: solid;
        border-right-color: #5C5C5C;
        box-sizing: border-box;
    }

    #child1 {
        width: 33.33;
        background-repeat: repeat-x;
        background-position: center center;
        <? set_radius("25px",false,false,true,false,true);?>
        float: left;
        background-color: #fff;
    }
    #child2 {
        width: 33.33;
        background-repeat: repeat-x;
        background-position: center center;
        background-color: #0CF;
    }

    #child3 {
        <? set_radius("25px",false,true,false,true,false);?>
        background-repeat: repeat-x;
        background-position: center center;
        width: 33.33;
        float: right;
        background-color: #F00;
    }

HTML:

<div class="parent">
          <div class="child_calss" id="child1"></div><div class="child_calss" id="child2"></div><div class="child_calss" id="child3"></div></div>

最佳答案

在你的 CSS 中:

parent{
    overflow: hidden;
}

那么您也不必为匹配子项上的 border-radius 而烦恼。

编辑

我创建了 this jsfiddle演示:

  1. children 不需要border-radius
  2. overflow: hidden 当子项重叠时将它们舍入
  3. 子项上不必要的 background- 属性已删除
  4. 小比例的预期行为

更新

关于此的另一个说明: 如果您希望 CSS/HTML 为您执行逻辑(而不是将最后一个元素从栏中删除),那么您对 ​​CSS 和 HTML 的作用有明显的误解。

我已经更新了 jsfiddle为该问题提供一种补丁修复。第三个 child 绝对定位在最右边,所以它永远留在栏中。

更新

最后,here's the bug在没有正确裁剪背景的 Webkit 中。看来你现在无能为力,除了可能是这样的:

<div class="hasBorder hasBorderRadius">
    <div class="hasBorderRadius hasHiddenOverflow">
        <div class="containsContent">
        </div>
    </div>
</div>

关于javascript - 当宽度为 2% 时,子 div 重叠圆形(带半径)容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9161826/

相关文章:

javascript - 围绕中心旋转图标

javascript - 从 'click' 事件处理程序返回特定的 DOM 元素

javascript - 从表格单元格中获取变量

html - ViewerJS 未加载我的 pdf 文档

javascript - JQuery 每个函数用 HTML 图像的属性填充数组

javascript - 当使用 angular2 在 table1 中单击元素时,如何聚焦 table2 中的元素

javascript - Express-Validator 和 req.getValidationResult()

javascript - 为什么以及如何在 javascript 中使用 IIFE

javascript - jQuery - 增加/减少跨度值

javascript - 在输入数字的向上/向下按钮处检测不同的事件