Border-radius and padding not playing nice

后端 未结 5 1594
萌比男神i
萌比男神i 2020-12-29 23:49

I\'m having trouble trying to get a radius on images. I\'ve simplified my problem and exaggerated the variables for demonstration purposes.

CSS:

相关标签:
5条回答
  • 2020-12-30 00:29

    Late but somehow found the solution for it. you cannot make a circle using it but you can make use of it by making a slight radius below is an example of my solution.

    I need 10px padding and 5px radius for my image, added together border-radius:15px worked fine for me

    I Hope the explanation was a bit better.

    0 讨论(0)
  • 2020-12-30 00:34

    This is a byproduct of applying both padding and a border-radius to the same element in some browsers (mostly IE and safari). The border-radius changes the curvature of the border component of the box model, which surrounds the padding component.

    In addition to the other answers, another interesting thing that seems to fix the issue is adding a border line. If you don't want to see the border, you could use border: 1px solid transparent, like this:

    .invisible-border {
        border: 1px solid transparent;
    }
    

    Demo in jsFiddle

    screenshot

    0 讨论(0)
  • 2020-12-30 00:41

    Set the padding on "wrap" not on the image (setting paddings on images does not make much sense :)), that should fix your problem.

    0 讨论(0)
  • 2020-12-30 00:45

    Your border radius will be outside of the padding, try setting margins instead which will space outside of the border.

    0 讨论(0)
  • 2020-12-30 00:48

    Had the same problem with a span instead of an img. Not exactly the same scenario since both tags have different display values (see this SO thread).

    In my case, setting display:inline-block to the span fixed everything.

    0 讨论(0)
提交回复
热议问题