【问题标题】:Image Overflow set to hidden but still not working图像溢出设置为隐藏但仍然无法正常工作
【发布时间】:2021-01-04 23:58:10
【问题描述】:

我有一个图像,即使它的父级设置为overflow: hidden 仍会溢出并在页面上创建水平滚动。 Shown here

以下是相关代码:

    .section2img {
        overflow-x: hidden !important;
        height: min-content;
        position: relative;
        width: 50vw;
        right: -60%;
        top: 0;
    }

    .section2 img {
        position: relative;
        overflow-x: hidden !important;
    }
GitRepo if needed

【问题讨论】:

  • 您是否尝试将body 设置为overflow-x: hidden
  • 是的,bodyhtml 都设置为 overflow-x: hidden
  • 你能发个minimum, reproducible example吗?

标签: css image styles overflow parent-child


【解决方案1】:

所以你可以做的是设置img的宽度使其与网站匹配,然后在img中添加object-fit: cover;,它所做的就是将溢出的部分剪掉。

【讨论】:

    猜你喜欢
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多