当前位置:首页 > CSS

css制作手机模型

2026-03-12 04:04:51CSS

使用CSS制作手机模型

通过CSS的边框、阴影和伪元素可以创建一个简单的手机模型。以下是实现方法:

HTML结构

css制作手机模型

<div class="phone">
  <div class="screen"></div>
  <div class="home-button"></div>
</div>

CSS样式

.phone {
  width: 300px;
  height: 600px;
  background: #111;
  border-radius: 40px;
  position: relative;
  box-shadow: 0 0 0 8px #333, 0 0 30px rgba(0,0,0,0.5);
}

.screen {
  width: 280px;
  height: 500px;
  background: #fff;
  border-radius: 20px;
  position: absolute;
  top: 50px;
  left: 10px;
}

.home-button {
  width: 60px;
  height: 60px;
  background: #333;
  border-radius: 50%;
  position: absolute;
  bottom: 20px;
  left: 120px;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.phone::before {
  content: '';
  width: 80px;
  height: 10px;
  background: #333;
  border-radius: 5px;
  position: absolute;
  top: 20px;
  left: 110px;
}

添加细节增强效果

为手机模型添加摄像头和音量按钮等细节:

css制作手机模型

.phone::after {
  content: '';
  width: 20px;
  height: 60px;
  background: #333;
  position: absolute;
  top: 120px;
  left: -5px;
  border-radius: 5px 0 0 5px;
}

.screen::before {
  content: '';
  width: 15px;
  height: 15px;
  background: #222;
  border-radius: 50%;
  position: absolute;
  top: 15px;
  left: 15px;
}

.screen::after {
  content: '';
  width: 40px;
  height: 5px;
  background: #222;
  position: absolute;
  top: 22px;
  left: 40px;
  border-radius: 5px;
}

响应式调整

通过媒体查询使手机模型适应不同屏幕尺寸:

@media (max-width: 600px) {
  .phone {
    width: 200px;
    height: 400px;
    border-radius: 25px;
  }

  .screen {
    width: 180px;
    height: 300px;
    top: 40px;
    border-radius: 15px;
  }

  .home-button {
    width: 40px;
    height: 40px;
    bottom: 15px;
    left: 80px;
  }
}

添加交互效果

使用CSS动画让手机模型更加生动:

.screen {
  transition: all 0.3s ease;
}

.phone:hover .screen {
  background: linear-gradient(135deg, #6e8efb, #a777e3);
}

.home-button:active {
  transform: scale(0.9);
  background: #555;
}

这些CSS技巧可以创建出具有基本外观和交互效果的手机模型,通过调整尺寸、颜色和细节可以模拟不同品牌的手机外观。

标签: 模型手机
分享给朋友:

相关文章

vue实现手机振动

vue实现手机振动

实现手机振动的基本方法 在Vue中实现手机振动功能可以通过浏览器的Vibration API。该API允许控制设备的振动硬件,适用于移动设备和部分桌面设备。 检查浏览器支持情况 在使用Vibrati…

vue实现手机震动

vue实现手机震动

Vue 中实现手机震动的方法 在 Vue 项目中可以通过调用浏览器的 Vibration API 实现手机震动功能。以下是具体实现方式: 检测浏览器支持性 在调用震动功能前需检查浏览器是否支持该 A…

react模型之间如何通信

react模型之间如何通信

组件间通信方法 父组件向子组件传递数据 通过props传递数据,子组件通过this.props(类组件)或直接解构props(函数组件)接收。 示例: // 父组件 <ChildCompo…

react实现手机键盘

react实现手机键盘

React 实现手机键盘的方法 在 React 中实现手机键盘可以通过自定义组件或使用第三方库来完成。以下是几种常见的方法: 自定义数字键盘组件 创建一个自定义的数字键盘组件,适用于输入密码、验证码…

js实现手机滑动效果

js实现手机滑动效果

实现基础滑动效果 使用touchstart、touchmove和touchend事件监听触摸操作: let startX, moveX; const slider = document.queryS…

js实现手机旋转

js实现手机旋转

监听设备方向变化 使用 window.addEventListener 监听 deviceorientation 事件,该事件在设备方向变化时触发。事件对象包含 alpha(绕Z轴旋转角度)、beta…