Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div with diagonal bottom border

Tags:

css

How can I make a div with diagonal bottom and with border?
I know that I can use clip-path, but by this way I can't make a border (example: https://jsfiddle.net/s976/qopxf6mj/4/)

Example

I saw "Creating a diagonal line/section/border with CSS" but it's not about enabling css border for diagonal container.

like image 392
Shimon S Avatar asked Dec 05 '25 12:12

Shimon S


1 Answers

You can try the use of skew transformation like below:

.container {
  width: 300px;
  height: 200px;
  background: url(https://picsum.photos/id/1002/800/800) center/cover;
  overflow: hidden;
}

.box {
  height: 70%;
  border-bottom: 10px solid red;
  transform: skewY(-15deg);
  transform-origin: left;
  position: relative;
  overflow: hidden;
}

.box:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url(https://picsum.photos/id/12/800/800) center/cover;
  transform: skewY(15deg);
  transform-origin: left;
}
<div class="container">
  <div class="box">

  </div>
</div>

Or clip-path combined with some gradient like below:

.container {
  width: 300px;
  height: 200px;
  background: url(https://picsum.photos/id/1002/800/800) center/cover;
}

.box {
  height: 70%;
  border-bottom: 10px solid red;
  background: 
    linear-gradient(to bottom right,transparent 49.5%,red 50%) bottom/100% 80px no-repeat,
    url(https://picsum.photos/id/12/800/800) center/cover;
  clip-path:polygon(0 0,100% 0, 100% calc(100% - 80px),0 100%)
}
<div class="container">
  <div class="box">

  </div>
</div>

You can optimze the last code to use only one element and some variables

.container {
  width: 300px;
  height: 200px;
  background: url(https://picsum.photos/id/1002/800/800) center/cover;
  --angle:80px;     /* Control the angle*/
  --thickness:10px; /* Control the thickness of the line */
}

.container:before{
  content:"";
  display:block;
  height: 70%;
  border-bottom: var(--thickness) solid red;
  background: 
    linear-gradient(to bottom right,transparent 49.2%,red 50%) bottom/100% var(--angle) no-repeat,
    url(https://picsum.photos/id/12/800/800) center/cover;
  clip-path:polygon(0 0,100% 0, 100% calc(100% - var(--angle)),0 100%)
}
<div class="container">

</div>

<div class="container" style="--angle:40px;--thickness:5px">

</div>
like image 178
Temani Afif Avatar answered Dec 12 '25 15:12

Temani Afif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!