如何使顶部和底部边框成三角形? [英] How to triangle top and bottom border?

查看:108
本文介绍了如何使顶部和底部边框成三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下图所示,我正在尝试使div的底部和顶部弯曲或成三角形,但我不知道该怎么做.我只是尝试了几次,但是无法达到目的.那么如何在psuedo之前使用after呢?伪装无关紧要,但我想知道怎么做?

As you can see in the image below, I am trying to warp or triangle my div from bottom and top, but I have no idea how to do it. I just tried a couple of times to do it, but I couldn't achieve the result. So how can I make it using after,before psuedo? It doesn't matter make with psuedo, but I wonder that how to do it?

这是我的代码:

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>

推荐答案

使用变换和透视图的想法,您将获得边界,边界半径以及渐变:

An idea using transformation and perspective where you will have the border, border-radius also the gradient:

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>

您还可以添加阴影并轻松更改渐变:

You can also add the shadow and easily change the gradient:

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>

这篇关于如何使顶部和底部边框成三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆