代码 css模拟了MacBook的外观

2024-11-18 14:07:40 +0800 CST views 542

该文本是一个HTML文档,模拟了MacBook的外观。使用CSS样式定义了MacBook的屏幕、摄像头孔、底部和反光效果。屏幕中嵌入了一个iframe,用于加载外部内容。整体设计注重细节,如边框、阴影和反光效果,旨在提供真实的视觉体验。

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MacBook 模拟</title>
    <style>
        body {
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background: radial-gradient(circle at center, white, #C8C8C8);
        }

        .macbook {
            font-size: 20px;
            width: 900px; /* 将宽度设为900px */
            display: flex;
            align-items: center;
            flex-direction: column;
        }

        .screen {
            height: 500px; /* 将高度设为500px */
            width: 800px;
            background: black;
            border: 0.3em solid #c0c0c0; /* 更接近真实的银色边框 */
            border-radius: 1em 1em 0 0;
            position: relative;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); /* 添加阴影效果 */
        }

        /* 摄像头孔 */
        .camera {
            width: 8px;
            height: 8px;
            background-color: #333;
            border-radius: 50%;
            position: absolute;
            top: 10px;
            left: 50%;
            transform: translateX(-50%);
            z-index: 2;
        }

        /* 在屏幕上添加 iframe 用于显示内容 */
        .screen iframe {
            border: none;
            margin: 4.2% 3.2%;
            width: calc(100% - 6.4%); /* 计算宽度,减去左右的 margin */
             height: calc(100% - 13.4%); /* 计算高度,减去上下的 margin */
        }

        /* 模拟屏幕反光效果 */
        .screen::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            /*background: radial-gradient(*/
            /*    circle at right bottom,*/
            /*    rgba(255, 255, 255, 0.4) 75%,*/
            /*    rgba(255, 255, 255, 0.6) 75%*/
            /*);*/
            margin: 4.2% 3.2%;
            pointer-events: none; /* 不影响 iframe 操作 */
        }

        /* 底部的 Base 部分 */
        .base {
            height: 0.7em;
            width: inherit;
            background: linear-gradient(
                white,
                white 55%,
                #999 60%,
                #222 90%,
                rgba(0, 0, 0, 0.1) 100%
            );
            border-radius: 0 0 10% 10% / 0 0 50% 50%;
            position: relative;
        }

        /* Base 部分的反光效果 */
        .base::before {
            content: '';
            position: absolute;
            width: inherit;
            height: 55%;
            background: linear-gradient(
                to right,
                rgba(0, 0, 0, 0.5) 0%,
                rgba(255, 255, 255, 0.8) 1%,
                rgba(0, 0, 0, 0.4) 4%,
                transparent 15%,
                rgba(255, 255, 255, 0.8) 50%,
                transparent calc(100% - 15%),
                rgba(0, 0, 0, 0.4) calc(100% - 4%),
                rgba(255, 255, 255, 0.8) calc(100% - 1%),
                rgba(0, 0, 0, 0.5) 100%
            );
        }

        /* Base 底部的阴影 */
        .base::after {
            content: '';
            position: absolute;
            width: 3em;
            height: 0.2em;
            background: #ddd;
            left: calc(50% - 3em / 2);
            box-shadow:
                inset -0.5em -0.1em 0.3em rgba(0, 0, 0, 0.2),
                inset 0.5em 0.1em 0.3em rgba(0, 0, 0, 0.2);
            border-radius: 0 0 7% 7% / 0 0 95% 95%;
        }
    </style>
</head>
<body>

    <div class="macbook">
        <div class="screen">
            <!-- 摄像头孔 -->
            <div class="camera"></div>
            <!-- 使用 iframe 加载内容 -->
            <iframe src="https://www.chenxutan.com"></iframe>
        </div>
        <div class="base"></div>
    </div>

</body>
</html>

images

复制全文 生成海报 网页设计 前端开发 用户界面 CSS样式

推荐文章

ElasticSearch集群搭建指南
2024-11-19 02:31:21 +0800 CST
Hypothesis是一个强大的Python测试库
2024-11-19 04:31:30 +0800 CST
Vue3中的v-slot指令有什么改变?
2024-11-18 07:32:50 +0800 CST
JavaScript数组 splice
2024-11-18 20:46:19 +0800 CST
Golang中国地址生成扩展包
2024-11-19 06:01:16 +0800 CST
在Vue3中实现代码分割和懒加载
2024-11-17 06:18:00 +0800 CST
js常用通用函数
2024-11-17 05:57:52 +0800 CST
nuxt.js服务端渲染框架
2024-11-17 18:20:42 +0800 CST
Vue3中如何实现响应式数据?
2024-11-18 10:15:48 +0800 CST
Rust 并发执行异步操作
2024-11-18 13:32:18 +0800 CST
维护网站维护费一年多少钱?
2024-11-19 08:05:52 +0800 CST
npm速度过慢的解决办法
2024-11-19 10:10:39 +0800 CST
前端如何优化资源加载
2024-11-18 13:35:45 +0800 CST
Go 单元测试
2024-11-18 19:21:56 +0800 CST
程序员茄子在线接单