代码 纯CSS绘制iPhoneX的外观

2024-11-19 06:39:43 +0800 CST views 579

该文本展示了如何使用纯CSS绘制iPhoneX的外观,包括设备的尺寸、框架样式、状态栏、内容区和按钮等。通过CSS样式设置,创建了一个模拟iPhoneX的网页结构,并嵌入了百度的内容。代码中详细定义了各个部分的样式和布局,适合前端开发者学习和参考。

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>iPhone X 纯CSS绘制 </title>
    <style>
        /* 全局样式,清除默认的边距和内边距 */
        * {
            margin: 0;
            padding: 0;
        }

        /* 设备的基础样式 */
        .device *,
        .device *::before,
        .device *::after {
            box-sizing: border-box;
            display: block;
        }

        .device {
            margin: 50px auto;
            position: relative;
        }

        /* iPhone X 的尺寸设定 */
        .iphone-x {
            height: 694px;
            width: 342px;
        }

        /* iPhone X 框架样式 */
        .iphone-x .frame {
            background: #222;
            border-radius: 54px;
            box-shadow: inset 0 0 0 2px #606467, inset 0 0 0 6px #e2e3e4;
            height: 694px;
            padding: 22px;
            width: 342px;
            z-index: 1;
        }

        /* 手机内容区,替换为iframe */
        .iphone-x .content {
            border-radius: 32px;
            height: 650px;
            width: 300px;
            position: relative;
            overflow: hidden;
                padding-top: 22px;
    background-color: #fff;
        }

        .iphone-x iframe {
            width: 100%;
            height: 100%;
            border: none;
        }

        /* 顶部状态栏 */
        .status-bar {
            position: absolute;
            top: 8px;
                top: 26px;
    left: 31px;
            height: 20px;
            z-index: 200;
            display: flex;
            justify-content: space-between;
            padding: 0 12px;
            font-size: 14px;
            color: white;
            font-family: sans-serif;
            align-items: center;
            width: 84%;
        }

        .status-bar .left {
            display: flex;
            align-items: center;
            color:#707070;
        }

        .status-bar .right {
            display: flex;
            align-items: center;
        }

        .signal, .wifi, .battery {
            width: 12px;
            height: 12px;
            margin-left: 4px;
            background-size: contain;
            background-repeat: no-repeat;
        }

        .signal {
            background-image: url('phone-signal-full.svg');
        }

        .wifi {
            background-image: url('WIFI.svg');
        }

        .battery {
            background-image: url('80dianliang.svg');
        }

        /* 底部的Home横条 */
        .home-indicator {
            position: absolute;
            bottom: 28px;
            left: 50%;
            width: 120px;
            height: 5px;
            background-color: #ccc;
            border-radius: 3px;
            transform: translateX(-50%);
            z-index: 200;
        }

        /* iPhone X 顶部和底部的天线 */
        .iphone-x .stripe::after,
        .iphone-x .stripe::before {
            border: solid rgba(51, 51, 51, .25);
            border-width: 0 6px;
            content: "";
            height: 5px;
            left: 0;
            position: absolute;
            width: 100%;
            z-index: 9;
        }

        .iphone-x .stripe::after {
            top: 68px;
        }

        .iphone-x .stripe::before {
            bottom: 68px;
        }

        /* iPhone X 顶部的听筒区域 */
        .iphone-x .header {
            background: #222;
            border-bottom-left-radius: 16px;
            border-bottom-right-radius: 16px;
            height: 24px;
            left: 50%;
            margin-left: -82px;
            position: absolute;
            top: 22px;
            width: 164px;
            z-index: 199;
        }

        .iphone-x .header::after,
        .iphone-x .header::before {
            content: "";
            height: 6px;
            position: absolute;
            top: 0;
            width: 6px;
        }

        .iphone-x .header::after {
            background: radial-gradient(circle at bottom left, transparent 0, transparent 75%, #222 75%, #222 100%);
            left: -6px;
        }

        .iphone-x .header::before {
            background: radial-gradient(circle at bottom right, transparent 0, transparent 75%, #222 75%, #222 100%);
            right: -6px;
        }

        /* 传感器样式 */
        .iphone-x .sensors::after,
        .iphone-x .sensors::before {
            content: "";
            position: absolute;
        }

        .iphone-x .sensors::after {
            background: #444;
            border-radius: 2.5px;
            height: 5px;
            left: 50%;
            margin-left: -20px;
            top: 4px;
            width: 40px;
        }

        .iphone-x .sensors::before {
            background: #444;
            border-radius: 50%;
            height: 11px;
            left: 50%;
            margin-left: 30px;
            top: 1px;
            width: 11px;
        }

        /* 左侧的音量按钮 */
        .iphone-x .btns {
            background: #606467;
            height: 26px;
            left: -2px;
            position: absolute;
            top: 92px;
            width: 3px;
        }

        .iphone-x .btns::after,
        .iphone-x .btns::before {
            background: #606467;
            content: "";
            height: 50px;
            left: 0;
            position: absolute;
            width: 3px;
        }

        .iphone-x .btns::after {
            top: 48px;
        }

        .iphone-x .btns::before {
            top: 112px;
        }

        /* 右侧电源按钮 */
        .iphone-x .power {
            background: #606467;
            height: 80px;
            position: absolute;
            right: -2px;
            top: 160px;
            width: 3px;
        }
    </style>
</head>
<body>

    <div class="device iphone-x">
        <!-- 外部轮廓 -->
        <div class="frame">
            <!-- 顶部状态栏 -->
            <div class="status-bar">
                <div class="left">
                    <span class="time">10:19</span>
                    
                </div>
                <div class="right">
                    <div class="signal"></div>
                    <div class="wifi"></div>
                    <div class="battery"></div>
                </div>
            </div>

            <!-- 内容区域,加载百度 -->
            <div class="content">
                <iframe src="//m.baidu.com" id="myIframe"></iframe>
            </div>
            
            <!-- 底部的Home横条 -->
            <div class="home-indicator"></div>
        </div>

        <!-- 天线 -->
        <div class="stripe"></div>

        <!-- 听筒孔 -->
        <div class="header">
            <div class="sensors"></div>
        </div>

        <!-- 按键 -->
        <div class="btns"></div>
        <div class="power"></div>
    </div>

</body>
</html>

images

复制全文 生成海报 前端开发 网页设计 CSS iPhone 技术

推荐文章

Python 微软邮箱 OAuth2 认证 Demo
2024-11-20 15:42:09 +0800 CST
JavaScript设计模式:组合模式
2024-11-18 11:14:46 +0800 CST
PHP 如何输出带微秒的时间
2024-11-18 01:58:41 +0800 CST
关于 `nohup` 和 `&` 的使用说明
2024-11-19 08:49:44 +0800 CST
PHP 允许跨域的终极解决办法
2024-11-19 08:12:52 +0800 CST
HTML和CSS创建的弹性菜单
2024-11-19 10:09:04 +0800 CST
支付页面html收银台
2025-03-06 14:59:20 +0800 CST
PHP 8.4 中的新数组函数
2024-11-19 08:33:52 +0800 CST
pycm:一个强大的混淆矩阵库
2024-11-18 16:17:54 +0800 CST
宝塔面板 Nginx 服务管理命令
2024-11-18 17:26:26 +0800 CST
如何配置获取微信支付参数
2024-11-19 08:10:41 +0800 CST
虚拟DOM渲染器的内部机制
2024-11-19 06:49:23 +0800 CST
Vue中如何使用API发送异步请求?
2024-11-19 10:04:27 +0800 CST
robots.txt 的写法及用法
2024-11-19 01:44:21 +0800 CST
Python实现Zip文件的暴力破解
2024-11-19 03:48:35 +0800 CST
程序员茄子在线接单