代码之家  ›  专栏  ›  技术社区  ›  Nicolas Frbezar

隐藏的Css溢出将不起作用,尽管相对于父级的位置

  •  2
  • Nicolas Frbezar  · 技术社区  · 6 年前

    我想隐藏子对象的某些部分,以便父容器之外的所有内容都不可见(因此我的部分图片应根据容器的高度进行裁剪)

    我遵循了很多论坛的答案,告诉我把容器放到相对位置(我的必须是相对的,所以这不是问题)

    .img-container {
      margin : auto;
      overflow:hidden;
      width:250px;
      position: relative;
      height: 250px;
      border : 5px dotted gray;
    }
    
    .img-container object, .img-container img{
      position : absolute;
      display: inline-block;
    }
    
    .img1{
      top : 0px;
      left : 0px;
      width:60%;
    }
    
    .img2{
      width: 52%;
      left :120px;
      top:50px;
    }
    <div class="img-container">
      <object class='img1' data='https://svgshare.com/i/6Pz.svg'>
    
      </object>
      <object class='img2' data='https://svgshare.com/i/6Pz.svg'>
    
      </object>
    </div>

    https://jsfiddle.net/u0upm3j3/2/

    答复:

    好吧好吧。。。我不明白的是:它现在起作用了。

    我做了什么?除了重新启动Chrome,什么都没有。

    感谢D3nj、Cavdi的回答,感谢Creaforge和Daniel的评论,很抱歉让您浪费了一点时间。但真的,我不明白它现在和以前是如何工作的。。。

    pos中的示例运行良好。

    2 回复  |  直到 6 年前
        1
  •  1
  •   D3nj1    6 年前
    img-container {
      margin : auto;
      overflow-x: hidden;
      overflow-y: hidden;
      width:250px;
      position: relative;
      height: 250px;
      border : 5px dotted gray;
    }
    
    .img-container object, .img-container img{
      position : absolute;
      display: inline-block;
    }
    
    .img1{
      top : 0px;
      left : 0px;
      width:60%;
    }
    
    .img2{
      width: 52%;
      left :120px;
      top:50px;
    }
    
        2
  •  0
  •   Cavdy    6 年前

    在css上使用此选项,并从图像样式中删除溢出

    *, html, body {
       overflow-x: hidden;
    }