如何三角形顶部和底部边框?

问题描述 投票:3回答:4

正如你可以在下面的图片中看到,我试图从底部和顶部变形或三角我的股利,但我不知道该怎么做。我只是尝试了几次这样做,但我不能达到的效果。所以,我怎样才能使它后使用,伪过吗?不要紧,使与伪,但我不知道该怎么办呢?

enter image description here

这里是我的代码:

body{
background:lightblue;;
}
.block{
    background-image: linear-gradient(to right, #314b56, #283b44, #1f2c32, #161e21, #0a0f11);
    border: 1px solid #fff;
    width: 300px;
    height: 150px;
    margin: 30px;
}
<div class="block"></div>
css css3 css-shapes linear-gradients
4个回答
4
投票

利用转型的角度,你将有边界,边界半径也渐变的想法:

body {
  background: lightblue;
}

.block {
  overflow: hidden;
  width: 300px;
  height: 200px;
  margin: 20px;
  position: relative;
  z-index:0;
}

.block::before,
.block::after {
  content: "";
  position: absolute;
  z-index:-1;
  border: 1px solid #fff;
  top: 0;
  bottom: 0;
  width: 50%;
  background-image: linear-gradient(to right, #314b56, #283b44, #1f2c32, #161e21, #0a0f11);
  background-size: 200% 100%;
}

.block::before {
  left: 0;
  border-right: 0;
  border-radius: 15px 0 0 15px;
  transform-origin: right;
  transform: perspective(100px) rotateY(-5deg);
}

.block::after {
  right: 0;
  border-left: 0;
  border-radius: 0 15px 15px 0;
  transform-origin: left;
  transform: perspective(100px) rotateY(5deg);
  background-position: right;
}
<div class="block"></div>

您还可以添加阴影,容易改变渐变:

body {
  background: lightblue;
}

.block {
  overflow: hidden;
  width: 300px;
  height: 200px;
  margin: 20px;
  position: relative;
  z-index:0;
  filter:drop-shadow(0 0 5px #000);
}

.block::before,
.block::after {
  content: "";
  position: absolute;
  z-index:-1;
  border: 1px solid #fff;
  top: 0;
  bottom: 0;
  width: 50%;
  background-image: linear-gradient(35deg, blue, red);
  background-size: 200% 100%;
}

.block::before {
  left: 0;
  border-right: 0;
  border-radius: 15px 0 0 15px;
  transform-origin: right;
  transform: perspective(100px) rotateY(-5deg);
}

.block::after {
  right: 0;
  border-left: 0;
  border-radius: 0 15px 15px 0;
  transform-origin: left;
  transform: perspective(100px) rotateY(5deg);
  background-position: right;
}
<div class="block"></div>

3
投票

你可以用clip-path做到这一点。有一个非常简单的工具,它可以帮助你:https://bennettfeely.com/clippy/

我做了一个例子,你与你的内容:

body {
  background: lightblue;
}

.block {
  background-image: linear-gradient(to right, #314b56, #283b44, #1f2c32, #161e21, #0a0f11);
  border: 1px solid #fff;
  width: 300px;
  height: 150px;
  margin: 30px;
  -webkit-clip-path: polygon(100% 80%, 50% 100%, 0 80%, 0 20%, 51% 0, 100% 20%);
  clip-path: polygon(100% 80%, 50% 100%, 0 80%, 0 20%, 51% 0, 100% 20%);
}
<div class="block"></div>

2
投票

这可以使用在::before::after伪元素CSS三角形来完成!我已经有色他们明亮的,所以你可以告诉发生了什么,但它应该是有点容易得到这些看起来他们你想要的方式。

body {
  background: lightblue;
}

.block {
  background-image: linear-gradient(to right, #314b56, #283b44, #1f2c32, #161e21, #0a0f11);
  border: 1px solid #fff;
  width: 300px;
  height: 150px;
  margin: 30px;
  position: relative;
}

.block::before,
.block::after{
  display: block;
  content: '';
  position: absolute;
  border: 150px solid transparent;
}

.block::before {
  border-top-width: 0;
  border-bottom-width: 25px;
  border-bottom-color: red;
  top: -25px;
}

.block::after {
  border-bottom-width: 0;
  border-top-width: 25px;
  border-top-color: green;
  bottom: -25px;
}
<div class="block"></div>

0
投票

调整测量以满足您的确切形状的要求。这使一些接近你在找什么。

body{
background:lightblue;;
}
.block{ position: 
relative; width:200px; 
height: 150px;
margin: 20px 0;
background: red;
border-radius: 50% / 10%;
background-image: linear-gradient(to right, #314b56, #283b44, #1f2c32, #161e21, #0a0f11);:
 }


}
.block:before
{ content: '';
position: absolute;
top: 20%; 
bottom: 20%; 
right: -5%; 
left: -5%; 
background: inherit;
border-radius: 5% / 50%;
}
<div class="block"></div>
© www.soinside.com 2019 - 2024. All rights reserved.