RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 645732
Accepted
Alexandr_TT
Alexandr_TT
Asked:2020-03-29 20:04:50 +0000 UTC2020-03-29 20:04:50 +0000 UTC 2020-03-29 20:04:50 +0000 UTC

一个角度的三种背景颜色

  • 772

我怎样才能得到类似于这张图片的背景:

在此处输入图像描述

只有 3 种颜色来自顶角,如旭日形。

也许最好使用普通图像PNG或SVG背景图像?

资源

html
  • 7 7 个回答
  • 10 Views

7 个回答

  • Voted
  1. Best Answer
    HamSter
    2020-03-29T20:32:20Z2020-03-29T20:32:20Z

    好吧,这样一个 css 上的“曲线”版本使用border:

    .bg {
      position:absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      
      overflow: hidden;
      background: #16334a;
    }
    
    .bg:after {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      border-bottom: 100vh solid #204158; 
      border-left: 70vw solid transparent;
    }
    
    .bg:before {
      content: '';
      position: absolute;
      right: 0;
      top: 0;
      border-top: 70vh solid #0a253e; 
      border-right: 100vw solid transparent;
    }
    
    .inner {
      position: relative;
      z-index: 5;
      color: #ccc;
      text-transform: uppercase;
      font-family: Arial;
      text-align: center;
      top: 40%;
    }
    <div class="bg">
      <div class="inner">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. In, impedit.
      </div>
    </div>

    • 13
  2. Alexandr_TT
    2020-03-29T20:04:50Z2020-03-29T20:04:50Z

    SVG

    这可以通过SVG. 我用过三个polygon。它们被设置为背景图像。或者使用它们inline,以便您可以在它们上应用属性CSS。

    html, body {
      margin: 0;
      padding: 0;
    }
    .triple {
      width: 250px;
      height: 250px;
    }
    .triple:hover {
      width: 500px;
      height: 100px;
    }  
    <svg class="triple" viewBox="0 0 100 100" preserveAspectRatio="none">
      <polygon fill="#dd2" points="0,0 100,0 0,60" />
      <polygon fill="#bb2" points="0,60 100,0 30,100 0,100 " />
      <polygon fill="#992" points="30,100 100,0 100,100" />
    </svg>

    来自贡献者 @Persijn的答案的松散翻译 。

    • 9
  3. Sasha Omelchenko
    2020-03-31T22:37:24Z2020-03-31T22:37:24Z

    还有另一个渐变选项。

    body {
      margin: 0;
    }
    
    div {
      height: 100vh;
      background-image: linear-gradient(135.7deg, transparent 70vw, #000 70.1vw), linear-gradient(156.5deg, #ccc 40vw, #666 40.1vw);
    }
    <div></div>

    • 7
  4. Alexandr_TT
    2020-03-29T20:10:26Z2020-03-29T20:10:26Z

    CSS

    效果可以通过使用伪元素和变换来实现CSS。
    下面是代码片段。
    但我认为 usingCSS不是正确的选择。
    最好使用 PNG 图片。
    该代码段使用一对具有不同背景颜色的伪元素,skewed以所需的角度倾斜 ( ) 以提供三色效果。

    .bg {
      position: relative;
      height: 200px;
      width: 400px;
      padding: 4px;
      background: orange;
      overflow: hidden;
    }
    .bg:after,
    .bg:before {
      position: absolute;
      content: '';
      left: 0px;
      height: 100%;
      width: 100%;
      transform-origin: right top;
    }
    .bg:before {
      top: 0px;
      background: red;
      transform: skewY(-45deg);
    }
    .bg:after {
      top: -100%;
      background: yellow;
      transform: skewY(-15deg);
    }
    span {
      position: relative;
      z-index: 2;
    }
    
    /* Just for demo */
    .bg:hover {
      height: 200px;
      width: 500px;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
    <div class="bg">
      <span>Some content inside</span>
    </div>

    贡献者 @Harry对答案的粗略翻译 。

    • 6
  5. Sasha Omelchenko
    2020-03-29T22:44:25Z2020-03-29T22:44:25Z

    clip-path(FF 的 SVG 回退)和伪元素。

    body {
      margin: 0;
    }
    
    #clips {
      display: block;
      height:0;
      width:0;
      overflow: hidden;
    }
    
    div {
      height: 100vh;
      position: relative;
      background-color: #000;
    }
    
    div:before, div:after {
      position: absolute;
      content: '';
      width: 100%;
      height: 100%;
      -webkit-clip-path: polygon(0% 0%, 100% 0%, 0% 60%);
      clip-path: url(#clip1);
      clip-path: polygon(0% 0%, 100% 0%, 0% 60%);
      background-color: #ccc;
    }
    
    div:before {
      -webkit-clip-path: polygon(100% 0%, 60% 100%, 0% 100%, 0% 60%);
      clip-path: url(#clip2);
      clip-path: polygon(100% 0%, 60% 100%, 0% 100%, 0% 60%);
      background-color: #666;
    }
    <div></div>
    
    <svg id="clips">
      <defs>
        <clipPath clipPathUnits="objectBoundingBox" id="clip1">
          <polygon points="0,0 1,0 0,0.6" />
        </clipPath>
        <clipPath clipPathUnits="objectBoundingBox" id="clip2">
          <polygon points="1,0 0.6,1 0,1 0,.06" />
        </clipPath>
      </defs>
    </svg>

    • 5
  6. Stranger in the Q
    2020-11-04T00:06:05Z2020-11-04T00:06:05Z

    您可以旋转 2 个白色半透明矩形

    <svg viewbox="-250,0,250,150" style="background: steelblue;">
      <rect x=-500 height=150 width=500 fill=#fff4 transform=rotate(-22)></rect>
      <rect x=-500 height=150 width=500 fill=#fff4 transform=rotate(-44)></rect>
    <svg>

    • 3
  7. zhurof
    2022-09-25T00:49:19Z2022-09-25T00:49:19Z

    锥形渐变就是为这样的任务而设计的。

    body{
      margin: 0;
      height: 100vh;
      background: conic-gradient(from 180deg at right top, #204158 55deg,#16334a  55deg, #16334a 70deg, #0a253e 70deg);
    }

    • 1

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5