downstream1990
downstream1990

Reputation: 138

Border-radius not working with image

enter image description here

This is the code I currently have for this image

border-radius: 10px;
border: 3px solid transparent;
-moz-border-image: -moz-linear-gradient(top, #E2B0C7 0%, #BB96C2 100%);
-webkit-border-image: -webkit-linear-gradient(top, #E2B0C7 0%, #BB96C2 100%);
border-image: linear-gradient(to bottom, #E2B0C7 0%, #BB96C2 100%);
border-image-slice: 10;

I am trying to round the border corners by using:

border-radius: 10px;

But that is not rounding the corners for me. Any help is appreciated. Thank you in advance.

Upvotes: 7

Views: 31539

Answers (3)

Ramzy Syed
Ramzy Syed

Reputation: 31

I was struggling with this just now. Was using as an image as a background for a <div> and border-radius simply refused to work. The <div> had two sections - left and right. The left section had an image as a background whereas the right had a simple bg-color. I applied an overflow:hidden to the <div> and voila!

Upvotes: 2

Farid Karami
Farid Karami

Reputation: 229

you must use the div and image into div. like this code

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <style>
        div {
            background: linear-gradient(#ff0000 0%, #b200ff 50%, #ff0000 100%);
            padding: 10px;
            display: inline-block;
            border-radius: 20px;
        }
        img {
            width: 500px;
            border-radius: 20px;
            vertical-align: middle;
        }
    </style>
</head>
<body>
    <div>
        <img src="FK8.jpg" />
    </div>
</body>
</html>

best regards.

Upvotes: 8

jbrya029
jbrya029

Reputation: 492

Border-radius and border-image are not the same; however, you can get this working with a ::after pseudo-element.

See updated fiddle: https://jsfiddle.net/2u44tqzy/1/

img {
    position: relative;
    border: 4px solid transparent;
    border-radius: 10px;
    background: linear-gradient(orange, violet);
    background-clip: padding-box;
    background: linear-gradient(to bottom, #E2B0C7 0%, #BB96C2 100%);
    /* just to show box-shadow still works fine */
    box-shadow: 0 3px 9px black, inset 0 0 9px white;
}

img::after{
    position: absolute;
    top: -4px; 
    bottom: -4px;
    left: -4px; 
    right: -4px;
    background: linear-gradient(to bottom, #E2B0C7 0%, #BB96C2 100%);
    content: '';
    z-index: -1;
    border-radius: 16px;
}

Upvotes: 0

Related Questions