使用css给div添加一些几何元素背景

代码

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      margin: 0;
      background-color: #f0f0f0;
    }

    .banner {
      height: 200px;
      background-color: #0c2140;
      position: relative;
      overflow: hidden;
    }

    .circle {
      background: linear-gradient(to bottom, rgba(255, 255, 255, .05), rgba(255, 255, 255, .1));
      border-radius: 50%;
    }

    .circle-1 {
      height: 50px;
      width: 50px;
      position: absolute;
      top: 30px;
      left: 50px;
    }

    .circle-2 {
      height: 300px;
      width: 300px;
      position: absolute;
      top: 100px;
      left: 40px;
    }

    .circle-3 {
      height: 300px;
      width: 300px;
      position: absolute;
      top: -50px;
      left: 250px;
    }

    .circle-4 {
      height: 50px;
      width: 50px;
      position: absolute;
      top: 30px;
      right: 500px;
    }

    .circle-5 {
      height: 300px;
      width: 300px;
      position: absolute;
      top: -150px;
      right: -150px;
    }

  </style>
</head>

<body>
  <div class="banner">
    <div class="circle circle-1"></div>
    <div class="circle circle-2"></div>
    <div class="circle circle-3"></div>
    <div class="circle circle-4"></div>
    <div class="circle circle-5"></div>
  </div>
</body>

</html>

效果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
赛博朋克风格的背景通常都比较复杂,包含了许多几何形状、线条、渐变和特效等元素。以下是一种可能的实现方式: HTML结构: ```html <div class="cyber-bg"> <div class="grid"></div> <div class="lines"></div> <div class="dots"></div> <div class="glow"></div> </div> ``` CSS样式: ```css .cyber-bg { position: relative; width: 100%; height: 100vh; overflow: hidden; background-color: #1b1b1b; } .grid { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 1px, transparent 1px), linear-gradient(to right, rgba(255, 255, 255, 0.05) 1px, transparent 1px); background-size: 20px 20px; } .lines { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: linear-gradient(to right, rgba(255, 255, 255, 0.02) 2px, transparent 2px), linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 2px, transparent 2px); background-size: 50px 50px; animation: lines 10s linear infinite; } .dots { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px), radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px); background-position: 0 0, 25px 25px; background-size: 50px 50px; } .glow { position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; border-radius: 50%; background-color: rgba(0, 255, 255, 0.1); opacity: 0; animation: glow 5s linear infinite; } @keyframes lines { from { background-position: 0 0, 0 0; } to { background-position: 50px 50px, 25px 25px; } } @keyframes glow { 0% { opacity: 0; } 50% { opacity: 0.5; } 100% { opacity: 0; } } ``` 解释: 1. `.cyber-bg` 是最外层的容器,设置宽度为100%、高度为100vh,背景颜色为 #1b1b1b(深灰色)。 2. `.grid` 是一个全屏的网格背景使用渐变和 `background-size` 属性实现。 3. `.lines` 是一组斜线背景使用渐变和 `animation` 属性实现。通过动画将背景的位置随时间移动,形成动态效果。 4. `.dots` 是一组圆点背景使用径向渐变和 `background-position` 属性实现。 5. `.glow` 是一个发光的圆形背景使用圆形边框和透明度实现。通过动画将透明度随时间变化,形成发光效果。 6. 使用 `position: absolute` 属性将每个背景元素定位到父容器的左上角,使它们叠加在一起形成复杂的背景效果。 这只是一种实现方式,您可以根据自己的需求和创意进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值