How do I prevent an image from overflowing a rounded corner box?

前端 未结 10 818
盖世英雄少女心
盖世英雄少女心 2020-12-03 09:50

If I use this code, the image isn\'t clipped by the div\'s rounded corners (resulting in the image\'s square corners covering up the div\'s rounded ones):

&l         


        
10条回答
  •  佛祖请我去吃肉
    2020-12-03 10:03

    Try this workaround:

    1. The image in img tag is present and there you set the width and height.
    2. Then hide it with visibility:hidden. The width and height stay intact.
    3. After that you'll set the same source as background image an it will clipped.

    
      Pic
    
    
    #page .thumb {
    background-repeat: no-repeat;
    background-position: left top;
    border: 3px #e5dacf solid;
    display: block;
    float: left;}
    
    #page .thumb img {
    display: block;
    visibility: hidden;}
    

提交回复
热议问题