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

Viewed 2574

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!

3 Answers

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

.profile {
  position: relative;
  display: inline-block;
  width: 200px;
  height: 200px;
  border-top: 2px solid #000;
  border-left: 2px solid #000;
  border-right: 2px solid #000;
  padding: 20px;
  box-sizing: border-box;
  font-family: Arial, sans-serif;
}

.profile h2 {
  margin: 0 0 10px;
}

.profile p {
  font-size: 14px;
}

.profile .bottom {
  position: absolute;
  bottom: -30px;
  right: -2px;
  width: 180px;
  height: 30px;
  border-bottom: 2px solid #000;
  box-sizing: border-box;
  border-right: 2px solid #000;
}

.profile .bottom::before {
  content: '';
  position: absolute;
  left: -10px;
  bottom: -4px;
  width: 2px;
  height: 35px;
  background-color: #000;
  transform: rotate(-35deg);
}
<div class="profile">
  <h2>Name</h2>
  <p>Description</p>
  <div class="bottom"></div>
</div>

I think you're trying to cut the corner of an image instead of div, so you can do something like this:

body {
    background: url('https://www.lunapic.com/editor/premade/o-paint-bucket.gif');
}

.container {
    display: inline-block;
    width: 200px;
    height: 300px;
    overflow: hidden;
}

.container .image_container {
    width: 320px;
    height: 550px;
    overflow: hidden;
    display: block;
    position: relative;
    transform: rotate(45deg);
    margin-left: calc(260px - 360px);
    margin-top: -40px;
}

.container .image_container .image {
    transform: rotate(-45deg);
    margin-top: 10px;
    margin-left: -10px;
}
<div class="container">
  <div class="image_container">
    <div class="image">
      <img src="https://www.w3schools.com/css/img_fjords.jpg" />
    </div>
  </div>
</div>

Related