CSS 80的TRON网格 [英] CSS 80's TRON Grid

查看:77
本文介绍了CSS 80的TRON网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用CSS构建"80's TRON Grid"效果,但是在将其放置到所需位置时遇到了一些问题.

I'm wanting to build an "80's TRON Grid" effect with CSS but I'm running into a few issues with getting it where I want it.

类似

我的要求:

  • 使1面褪色为透明
  • 将其打包成一个漂亮的.class即可放在任何<element>上,并且可以正常工作
  • Fade 1 side to transparent
  • Package it up into a nice .class to put on any <element> and it just work

我使用2种不同的技巧尝试了2次.

I've made 2 attempts at this w/ 2 different techniques.

80年代网格#1(伪选择器)
https://codepen.io/oneezy/pen/MPQWBE
尽管这很完美,但是每次我想要效果时,在我的html中放入10个<div>都不是理想的选择.

80's Grid #1 (pseudo selectors)
https://codepen.io/oneezy/pen/MPQWBE
Although this works perfectly, it's not ideal to put 10 <div>'s in my html every time I want the effect.

body { background: black; }

.grid-container { 
	position: absolute; width: 200%; height: 100vh; bottom: 0; left: -50%; overflow: hidden; 
	transform: perspective(200px) rotateX(40deg) scale(1) translateZ(0);
	transform-origin: bottom;
	padding: 1px; 
	-webkit-background-clip: content-box; 
	-webkit-backface-visibility: hidden;
	outline: 1px solid transparent; 
	will-change: transform; 
}

.grid-line { height: 100%; width: 100%; position: absolute; }


.grid-line:before,
.grid-line:after  { content: ""; display: block; position: absolute; }
.grid-line:before { height: 5px; width: 100%; background: blue; }
.grid-line:after  { height: 100%; width: 5px; background-image: linear-gradient(transparent, blue); }

.grid-line:nth-child(1):before  { top: 0%;  opacity: 0; }
.grid-line:nth-child(2):before  { top: 10%; opacity: 0; }
.grid-line:nth-child(3):before  { top: 20%; opacity: .3; }
.grid-line:nth-child(4):before  { top: 30%; opacity: .4; }
.grid-line:nth-child(5):before  { top: 40%; opacity: .5; }
.grid-line:nth-child(6):before  { top: 50%; opacity: .6; }
.grid-line:nth-child(7):before  { top: 60%; opacity: .7; }
.grid-line:nth-child(8):before  { top: 70%; opacity: .8; }
.grid-line:nth-child(9):before  { top: 80%; opacity: .9; }
.grid-line:nth-child(10):before { top: 90%; opacity: 1; }
.grid-line:nth-child(11):before { top: calc(100% - 3px); }


.grid-line:nth-child(1):after  { left: 0%;  }
.grid-line:nth-child(2):after  { left: 10%; }
.grid-line:nth-child(3):after  { left: 20%; }
.grid-line:nth-child(4):after  { left: 30%; }
.grid-line:nth-child(5):after  { left: 40%; }
.grid-line:nth-child(6):after  { left: 50%; }
.grid-line:nth-child(7):after  { left: 60%; }
.grid-line:nth-child(8):after  { left: 70%; }
.grid-line:nth-child(9):after  { left: 80%; }
.grid-line:nth-child(10):after { left: 90%; }
.grid-line:nth-child(11):after { left: calc(100% - 3px); }

<section class="grid-container">
	<div class="grid-line"></div>
	<div class="grid-line"></div>
	<div class="grid-line"></div>
	<div class="grid-line"></div>
	<div class="grid-line"></div> 
	<div class="grid-line"></div>
	<div class="grid-line"></div>
	<div class="grid-line"></div>
	<div class="grid-line"></div>
	<div class="grid-line"></div>
	<div class="grid-line"></div>
</section>

80年代网格#2(线性渐变)
https://codepen.io/oneezy/pen/OaQNPe
这项技术非常理想,因为它允许我在1 <element>上使用1 .class,但是我不确定如何使其淡出.

80's Grid #2 (linear-gradient)
https://codepen.io/oneezy/pen/OaQNPe
This technique is ideal because it allows me to use 1 .class on 1 <element>, but I'm not sure how to make it fade out.

body { background: black; }

.grid-container { width: 100%; position: absolute; bottom: 0; left: 0; }

.grid-container:after { 
  
	transform: perspective(200px) rotateX(40deg) scale(2,1) translateZ(0);
  content: ""; display: block; position: absolute; bottom: 0; left: 0; right: 0; width: 100%; height: 100vh;
  padding: 1px; 
  -webkit-background-clip: content-box; 
  -webkit-backface-visibility: hidden;
  outline: 1px solid transparent;
  transform-origin: bottom center;
  will-change: transform; 
}

.grid-container:after {
  background-position: center bottom;
  background-size: 40px 40px;
  background-image: 
  linear-gradient(to right, blue 1px, transparent 0), 
  linear-gradient(to bottom, blue 3px, transparent 0);
}

<section class="grid-container">
</section>

预先感谢您的建议:D

Thanks in advance for your suggestions :D

推荐答案

您可以将mask-image与alpha渐变配合使用以实现所需的效果.

You can use mask-image with an alpha gradient to achieve the effect you're looking for.

.grid-container:after { 
   -webkit-mask-image: -webkit-gradient(linear, left 90%, left top, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
   mask-image: gradient(linear, left 90%, left top, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
}

在这里看看: https://codepen.io/JoahG/pen/QJQdJB

这篇关于CSS 80的TRON网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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