How to make CSS3 rounded corners hide overflow in Chrome/Opera

后端 未结 13 2097
无人及你
无人及你 2020-11-22 09:10

I need round corners on a parent div to mask content from its childen. overflow: hidden works in simple situations, but breaks in webkit based browsers and Oper

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 09:57

    If you are looking to create a mask for an image and position the image inside the container don't set the 'position: absolute' attribute. All you have to do is change the margin-left and margin-right. Chrome/Opera will adhere to the overflow: hidden and border-radius rules.

    // Breaks in Chrome/Opera.
        .container {
            overflow: hidden;
            border-radius: 50%;
            img {
                position: absolute;
                left: 20px;
                right: 20px;
            }
        }
    
    // Works in Chrome/Opera.
        .container {
            overflow: hidden;
            border-radius: 50%;
            img {
                margin-left: 20px;
                margin-right: 20px;
            }
        }
    

提交回复
热议问题