css 旋转背景从中间到 Angular 落

标签 css background-color css-transforms

我想在 CSS 中实现这个,对所有屏幕尺寸都有效: example

从屏幕的左侧到中间背景应该是蓝色的,从中上到右下角的背景应该是白色的。 这是我已经得到的:

<style>
.wrapper {
    position: fixed;
    z-index: 1;
    width: 100%;
    height: 100%;
    background: #297fca;
}
.right {
    position: fixed;
    z-index: 2;
    top: -70%;
    right: -50%;
    background: #fff;
    width: 100%;
    height: 100%;
    transform: translateY(50%) rotate(45deg);
  }
</style>
...
 <div class="wrapper">
    <div class="right">
    </div>

  </div>

这适用于某些屏幕尺寸,但不是通用解决方案。 我正在寻找仅 CSS 的解决方案。如果这不可能,SVG 方法也可以。

提前致谢。

最佳答案

您可以使用线性渐变轻松做到这一点。您需要其中两个,一个将创建一个方形来填充前 50%,第二个将创建三 Angular 形以填充剩余的 50%。

body {
  margin:0;
  height:100vh;
  background-image:
   linear-gradient(#297fca,#297fca),
   linear-gradient(to bottom left,transparent 49.8%,#297fca 50%);
  background-repeat:no-repeat;
  background-size:50.1% 100%; /* both gradient will fill 50% width and 100% height*/
  background-position:
    left, /* The first one placed on the left*/
    right /* The second one placed on the right*/
}

如果你不想要透明度,你可以像下面那样做:

body {
  margin:0;
  height:100vh;
  background:
   linear-gradient(to top right,transparent 49.8%,#fff 50%) 
    right -1px top 0
    /50% 100% 
    no-repeat,
   #297fca;
}

关于css 旋转背景从中间到 Angular 落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49500998/

相关文章:

ios - iPhone X 上 UIScrollView 左侧不需要的空白

css - 如何使用 CSS3 实现类似 Windows Phone 的 "tiled"3D 转换

html - Css - 动画背景图像 - 带循环的缩放效果

jquery - Select2 使用 Ajax 在运行时更改颜色

r - 为ggplot2中的每个图例分配不同的背景颜色

html - 为什么不显示除法的背景颜色?

css - 为什么 -moz-animation 不起作用?

css - CSS3透视属性到底是什么?

html - 垂直居中对齐 Bootstrap 4 Form-Group Row

javascript - 在移动屏幕中从纵向移动到横向再回到纵向时,窗口元素在垂直方向上变得不可见?