使用CSS的倾斜边框

Aru*_*til 3 css css3 css-shapes

我怎么能将div设置为喜欢下面的图像呢?

在此输入图像描述

Ale*_*lex 8

您可以将半三角形与伪元素一起使用。

.container {
  padding: 20px;
  background-color: #F8F8F8;
  max-width: 200px;
}
.rectangle {
  width: 200px;
  height: 100px;
  background-color: #003781;
  position: relative;
}
.rectangle:after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 25px 25px;
  border-color: transparent transparent #F8F8F8 transparent;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <div class="rectangle"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

提琴手

  • @ManojKumar 我们总是平行移动。 (2认同)

Jad*_*ine 5

试试这个:

HTML

<div class="main"></div>
<div class="cornered"></div>
Run Code Online (Sandbox Code Playgroud)

CSS

.main {
    width: 300px;
    height: 200px;
    background-color: blue;
}
.cornered {
    width: 260px;
    height: 0px;
    border-top: 40px solid blue;
    border-right: 40px solid white;
}
Run Code Online (Sandbox Code Playgroud)

你将有2个div像:

DIV main

在此输入图像描述

DIV cornered

在此输入图像描述

看看这个.