Search code examples
htmlcssbordercornerradius

How to cut a corner with CSS when background image is necessary?


enter image description here

The above is an image of a project I'm working on. This is how far I got:

enter image description here

Creating the box was fairly simple; however, now I have NO IDEA how to create this cut corner on the bottom left. I've tried a bunch of things already and most things work if the background isn't transparent but a block of color. Since the background needs to be this image, I can't make the cut corner work without having one side show a certain color. This is my code:

<div class="profile">
    // HTML content
</div>

<style>
   profile {
   border: 2px solid #fff;
   color: #fff;
   height: 100%;
   padding: 10px;
   width: 250px;
</style>

I've tried multiple things already, such as this here (not the exact code I used, but I followed this example):

.cut {
  border: none;
  position: relative;
}

.cut:before {
  content: "";
  position: absolute;
  bottom: 0;
  right: 0;
  border-bottom: 20px solid lightgrey;
  border-left: 20px solid #e67e22;
  width: 0;
}

This creates a cut corner, but with a block of a solid color and I need the image to be shown, not the color.

Does anyone have a clue how to do this? Suggestions are much appreciated. Thanks!


Solution

  • You may use before/after element to make the bottom part like this :

    .profile {
    position:relative;
    display:inline-block;
    margin:50px;
    border:1px solid #000;
    border-bottom:none;
    width:100px;
    height:200px;
    background:#ccc;
    }
    .profile:after {
    content:" ";
    position:absolute;
    border:1px solid #000;
    height:20px;
    width:80px;
    bottom:-20px;
    right:-1px;
    border-top:0;
    border-left:0;
    background:#ccc;
    }
    .profile:before {
    content:" ";
    position:absolute;
    border-bottom:1px solid #000;
    height:29px;
    width:29px;
    transform:rotate(45deg);
    bottom:-15px;
    left:6px;
    background:#ccc;
    }
    <div class="profile"></div>

    the bottom is split into tow part : a rectangle with only two border + a square with one border rotated with 45°

    Hope it helps

    NB : Becarefull when changing the dimensions