Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add rounded corners to a rectangle raster image

What is the best way to make something like a mask with rounded corners for an image using CSS/JS/HTML? So, I need to add rounded corners to a rectangle image. I thought about adding 4 graphic elements like this one alt text above the image at its corners to hide some little parts of the image. Here red color is, for example, for using on the red background page, and the element is for right top corner. The problem with this solution is that I can't use it on complex backgrounds, like gradients or other non-flat fill background. I know there is a masking feature that can be used in FireFox but I need some more generic solution that will work in other browsers well too. Thanks.

like image 846
Sergei Basharov Avatar asked Jan 21 '23 10:01

Sergei Basharov


2 Answers

You should be using CSS border-radius for this (as described in another answer). It does work for images.

What the previous answer missed is that you can support it in CSS in all browsers, including IE6/7/8 using a wonderful little hack called CSS3Pie.

like image 50
Spudley Avatar answered Jan 31 '23 16:01

Spudley


The best and simplest way is to use the CSS3 border-radius property:

.box {
    -moz-border-radius: 4px;
    -webkit-border-radius: 4px;
    border-radius: 4px;
}

It works in all modern browsers apart from IE8 (works in the new IE9 though).

like image 22
DisgruntledGoat Avatar answered Jan 31 '23 16:01

DisgruntledGoat