css实现正六边形嵌套圆心

要实现一个正六边形嵌套圆心,可以使用CSS的::before::after伪元素以及border-radius属性。以下是具体的解析和代码:

  1. 使用::before::after伪元素创建正六边形。
  2. 设置正六边形的背景色。
  3. 使用border-radius属性使正六边形的内角为60度。
  4. 在正六边形内部创建圆形,并设置其位置、大小和背景色。
  5. 使用border-radius属性使圆形的内角为50%,使其呈现圆形效果。
html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正六边形中间圆形</title>
    <style>
        .hexagon {
            position: relative;
            width: 200px;
            height: 100px;
            background-color: #F99B68;
            margin: 50px auto;
        }

        .hexagon::before,
        .hexagon::after {
            content: "";
            position: absolute;
            width: 0;
            height: 0;
            border-left: 100px solid transparent;
            border-right: 100px solid transparent;
        }

        .hexagon::before {
            bottom: 100%;
            border-bottom: 50px solid #F99B68;
            border-top: 50px solid #F99B68;
        }

        .hexagon::after {
            top: 100%;
            border-top: 50px solid #F99B68;
            border-bottom: 50px solid white;
        }

        .circle {
            position: absolute;
            top: 0px;
            left: 26%;
            width: 100px;
            height: 100px;
            background-color: white;
            border-radius: 50%;
        }
        .point {
            position: absolute;
            top: 25px;
            left: 25%;
            width: 50px;
            height: 50px;
            background-color: #F99B68;
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <div class="hexagon">
        <div class="circle">
            <div class="point"></div>
        </div>
    </div>
</body>
</html>
相关推荐
敲代码的彭于晏3 分钟前
Bean 生命周期完全图解:前端同学也能看懂的 Spring 核心机制
java·前端·后端
IT_陈寒9 分钟前
Redis内存飙升的锅,原来是我没搞懂这个过期策略
前端·人工智能·后端
云浪16 分钟前
前端二进制数组完全指南:ArrayBuffer、TypedArray、DataView 一次讲透
前端·javascript
张风捷特烈18 分钟前
Flutter 类库大揭秘#02 | path_provider 各平台实现
前端·flutter
铁皮饭盒1 小时前
26年bunjs, elysia+pg一把梭, redis都省了
前端·javascript·后端
lichenyang45314 小时前
Docker 学习笔记(一):为什么需要镜像、容器和仓库?
前端
kyriewen14 小时前
别再对着 TypeScript 报错发呆了:我把 10 个最常见的红色波浪线翻译成了人话
前端·javascript·typescript
IT_陈寒14 小时前
SpringBoot自动配置的坑,我的API突然就404了
前端·人工智能·后端
奇奇怪怪的15 小时前
Embedding 模型 10+ 横向评测
前端