CSS写一个手机

手机外形上来说就是长方形,然后加上圆角边框,如果是简单的平面图形,几分钟就可以用html标签和css写一个手机模型。但如果有高光,菱角等让手机展示的更逼真,可以用到css背景渐变属性。

预览页面:CSS画手机

先看看效果图:
 

手机完整代码:
 

<div class="phone">
  <div class="box">   
  </div>
  <!--other begin-->
  <div class="volume"></div>
  <div class="power"></div>
  <div class="camera"></div>
  <div class="receiver">
    <div></div>
  </div>
  <!--other end--> 
</div>

.phone {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 400px;
    height: 800px;
    margin-top: -400px;
    margin-left: -200px;
    border: 20px solid #000;
    border-radius: 60px;
}

.phone:before {
    content: "";
    position: absolute;
    width: 421px;
    height: 815px;
    box-shadow: 0px 0px 24px #fff;
    border-radius: 45px;
    left: -10px;
    top: -8px;
}

.phone:after {
    content: "";
    position: absolute;
    width: 382px;
    height: 751px;
    border: 16px solid #19191d;
    background: #19191d;
    border-top: 30px solid #19191d;
    border-bottom: 30px solid #19191d;
    border-radius: 41px;
    left: -6px;
    top: -6px;
}

.box {
    position: absolute;
    border: #19191d 1px solid;
    width: 423px;
    height: 817px;
    left: -12px;
    top: -10px;
    z-index: 9;
    border-radius: 50px;
    box-shadow: #2e2c2c 0 0 14px;
}

.box:before {
    content: "";
    position: absolute;
    width: 410px;
    height: 789px;
    border-radius: 50px;
    top: 10px;
    left: 6px;
    z-index: -1;
    background-size: 100%;
    background-position: bottom;
    background-image: linear-gradient(45deg, #46a7c0 50%, #185c92 50%, #185c92 100%);
}

.volume {
    width: 9px;
    height: 100px;
    border: #000 1px solid;
    background: linear-gradient(#8c8c8c, #000 9%, #222, #000 94%, #353535 100%);
    position: absolute;
    right: -25px;
    top: 125px;
    z-index: -1;
    border-radius: 20px;
}

.power {
    width: 9px;
    height: 46px;
    border: #000 1px solid;
    background: linear-gradient(#8c8c8c, #000 9%, #222, #000 94%, #353535 100%);
    position: absolute;
    right: -25px;
    top: 260px;
    z-index: -1;
    border-radius: 20px;
}

.receiver {
    position: absolute;
    top: -13px;
    left: 50%;
    margin-left: -50px;
    background: #000000;
    border: #484848 1px solid;
    width: 100px;
    height: 8px;
    z-index: 9;
    border-radius: 20px;
}

.receiver ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    margin: 1px;
    justify-content: space-around;
}

.receiver ul li {
    background: #303030;
    width: 1px;
    height: 1.5px;
    float: left;
    transform: skewX(-38deg);
}

.camera {
    position: absolute;
    width: 22px;
    height: 22px;
    background: #19191d;
    border-radius: 100%;
    top: 10px;
    left: 20px;
    z-index: 9;
}


.receiver div {
    width: 100px;
    height: 8px;
}

.receiver div:after {
    content: "";
    display: block;
    width: 95%;
    height: 83%;
    top: 1px;
    left: 3px;
    position: absolute;
    background-repeat: no-repeat;
    background-image: repeating-linear-gradient(to right, #434242, #000000 1px, rgba(255,255,255,0) 1px, rgba(255,255,255,0) 3px), repeating-linear-gradient(to right, #434242, #19191d 1px, rgba(255,255,255,0) 1px, rgba(255,255,255,0) 3px);
    background-size: 100% 50%;
    background-position: 0 0, 2px 4px;
    transform: skew(-25deg);
}


  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的小米页面HTMLCSS代码: HTML代码: ``` <!DOCTYPE html> <html> <head> <title>小米官网</title> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <header> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">小米手机</a></li> <li><a href="#">电视</a></li> <li><a href="#">笔记本</a></li> <li><a href="#">家电</a></li> <li><a href="#">智能硬件</a></li> </ul> </nav> </header> <section id="banner"> <h1>小米10 Pro</h1> <p>全球首款LPDDR5内存</p> <a href="#" class="button">了解更多</a> </section> <section id="products"> <h2>小米产品</h2> <div class="product"> <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/bd9c9f9d2acfe3d3ce9d4eb9b4e0e060.jpg?thumb=1&w=400&h=400"> <h3>小米电视</h3> <p>从 32 至 75 英寸,满足各种需求</p> <a href="#">了解更多</a> </div> <div class="product"> <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/3e9f5b09e7cbdc500c1d4bfa5ac1a0f5.jpg?thumb=1&w=400&h=400"> <h3>小米电脑</h3> <p>轻薄便携,助力高效办公和生活</p> <a href="#">了解更多</a> </div> <div class="product"> <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/3ac9d9c9e6f8f4d71d6d2fd4a464150a.jpg?thumb=1&w=400&h=400"> <h3>小米手机</h3> <p>强大性能搭载最新技术</p> <a href="#">了解更多</a> </div> <div class="product"> <img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/1b779f3c9a2b84fb1de4709b2f9d57a8.jpg?thumb=1&w=400&h=400"> <h3>小米家电</h3> <p>智能可控,让生活更美好</p> <a href="#">了解更多</a> </div> </section> <footer> <p>© 2021 小米</p> </footer> </body> </html> ``` CSS代码: ``` /* Reset CSS */ * { margin: 0; padding: 0; box-sizing: border-box; } /* Global Styles */ body { font-family: Arial, sans-serif; font-size: 16px; line-height: 1.5; color: #333; } a { text-decoration: none; color: #333; } ul { list-style: none; } /* Header Styles */ header { background-color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); position: fixed; top: 0; left: 0; width: 100%; z-index: 1; } nav { max-width: 1200px; margin: 0 auto; padding: 20px 0; } nav ul { display: flex; justify-content: space-between; align-items: center; } nav li { margin-right: 20px; } nav a { padding: 5px 10px; border-radius: 5px; transition: all 0.3s ease; } nav a:hover { background-color: #f5f5f5; } /* Banner Styles */ #banner { background-image: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/2cfdf03d7ae8b8c4b9eef46d3a53c54d.jpg?thumb=1&w=1920&h=408&f=webp&q=90); background-position: center; background-size: cover; height: 600px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; color: #fff; } #banner h1 { font-size: 60px; margin-bottom: 20px; } #banner p { font-size: 24px; margin-bottom: 30px; } .button { padding: 10px 30px; background-color: #ff6700; color: #fff; border-radius: 5px; transition: all 0.3s ease; } .button:hover { background-color: #ff5500; cursor: pointer; } /* Products Styles */ #products { max-width: 1200px; margin: 100px auto; display: grid; grid-template-columns: repeat(4, 1fr); grid-gap: 50px; } .product img { width: 100%; height: auto; } .product h3 { font-size: 24px; margin: 20px 0; } .product p { font-size: 16px; margin-bottom: 20px; } .product a { padding: 10px 20px; background-color: #f5f5f5; color: #333; border-radius: 5px; transition: all 0.3s ease; } .product a:hover { background-color: #ddd; cursor: pointer; } /* Footer Styles */ footer { background-color: #f5f5f5; padding: 20px; text-align: center; } ``` 你可以将上述代码复制到一个HTMLCSS文件中,然后在浏览器中打开HTML文件,就可以看到一个简单的小米官网页面了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值