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>
相关推荐
excel2 小时前
ES6 中函数的双重调用方式:fn() 与 fn\...``
前端
可乐爱宅着2 小时前
全栈框架next.js入手指南
前端·next.js
你的人类朋友4 小时前
什么是API签名?
前端·后端·安全
会豪6 小时前
Electron-Vite (一)快速构建桌面应用
前端
中微子6 小时前
React 执行阶段与渲染机制详解(基于 React 18+ 官方文档)
前端
唐某人丶6 小时前
教你如何用 JS 实现 Agent 系统(2)—— 开发 ReAct 版本的“深度搜索”
前端·人工智能·aigc
中微子6 小时前
深入剖析 useState产生的 setState的完整执行流程
前端
遂心_6 小时前
JavaScript 函数参数传递机制:一道经典面试题解析
前端·javascript
小徐_23337 小时前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
RoyLin7 小时前
TypeScript设计模式:适配器模式
前端·后端·node.js