移动换页面布局实战项目

1. html 结构

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>美食美客</title>
  <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.1.1/css/all.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
  <div id="flash">
    <img src="img/1.jpeg" alt="logo">
    <p>美食美客</p>
  </div>
  <div class="content">
    <header class="app-header">
      <div class="container">
        <img src="img/2.jpeg" class="logo">
        <p>美食美客</p>
        <input type="text" class="search" placeholder="搜索...">
      </div>
    </header>
    <div class="subheader">
      <div>
        <p>配送信息</p>
        <p>外卖小哥想你飞奔而来, 点击查看具体信息... 
          <i class="fafa-chevron-right"></i>
        </p>
      </div>
      <img src="img/3.jpeg" alt="">
    </div>
    <div class="grid container">
      <div class="item">
        <h4>火锅</h4>
        <p>没有什么是一顿火锅解决不了的...</p>
        <img src="img/4.jpeg" alt="">
      </div>
      
      <div class="item">
        <h4>烧烤</h4>
        <p>再天愿作比翼鸟, 在地就要吃烧烤</p>
        <img src="img/4.jpeg" alt="">
      </div>
    
      <div class="item">
        <h4>海鲜</h4>
        <p>甄选全球生鲜,尽享美食盛宴...</p>
        <img src="img/4.jpeg" alt="">
      </div>

      <div class="item">
        <h4>快餐</h4>
        <p>健康美味,无需等待...</p>
        <img src="img/4.jpeg" alt="">
      </div>

      <div class="item">
        <h4>下午茶</h4>
        <p>我有下午茶,你有时间吗...</p>
        <img src="img/4.jpeg" alt="">
      </div>

      <div class="item">
        <h4>西餐</h4>
        <p>感受西餐文化,体验异域风情...</p>
        <img src="img/4.jpeg" alt="">
      </div>
    </div>
  </div>
  <footer class="app-footer">
    <ul>
      <li><i class="fa fa-heart">收藏</i></li>
      <li><i class="fa fa-cart-arrow-down">订单</i></li>
      <li><i class="fa fa-user">我的</i></li>
      <li><i class="fa fa-map-marker">附近</i></li>
    </ul>
  </footer>
  <script>
    setTimeout(function () {
      document.getElementById('flash').classList.add('fade')
    }, 2000)
  </script>
</body>
</html>

2. css 样式

:root {
  --primary-color: #cc0000;
  --secondary-color: #7c0000;
}

/* reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html {
  height: 100%;
}
body {
  font-family: 'Roboto', sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.container {
  width: 90%;
  margin: 0 auto;
  padding: 10px;
  overflow: none;
}

/* hrader */
.app-header {
  background-color: var(--primary-color);
  box-shadow: 3px 3px 10px #888;
}

.app-header .container {
  display: flex;
  /* 纵向排列 */
  flex-direction: column;
  /* 上下居中 */
  align-items: center;
  /* 水平居中 */
  justify-content: center;
  padding: 15px 10px;
}

.app-header .logo {
  width: 40px;
}
.app-header p{
  color: #fff;
  font-size: 1.2rem;
  padding: 5px;
}
.app-header input {
  padding: 7px;
  width: 300px;
  border-radius: 3px;
}

/* subheader */
.subheader {
  background-color: var(--secondary-color);
  color: #fff;
  box-shadow: 3px 3px 10px #888;
  width: 90%;
  margin: 0 auto 16px auto;
  font-size: 14px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.subheader img {
  width: 40px;
}

.subheader p {
  margin: 4px;
}
/* grid */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 10px;
}
.grid .item {
  display: flex;
  border: 1px #ccc solid;
  flex-direction: column;
  padding: 10px;
  box-shadow: 1px 1px 2px #ccc;
}
.grid .item h4 {
  margin-bottom: 5px;
}
.grid .item p {
  font-size: 14px;
  color: var(--secondary-color);
  font-weight: bold;
  margin-bottom: 20px;
}
.grid .item img {
  width: 30px;
  align-self: flex-end;
}
/* footer */
.app-footer {
  background: #f4f4f4;
  color: #444;
  padding: 10px;
  font-size: 14px;
  margin-top: 10px;
}
.app-footer ul {
  display: flex;
  align-items: center;
  justify-content: space-around;
  list-style: none;
}
.app-footer ul li {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.app-footer ul li i {
  font-size: 22px;
}

/* flash */
#flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background-color: var(--primary-color);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 1s;
}

#flash p {
  color: #ffffff;
  font-size: 2rem;
}

#flash img {
  width: 150px;
}
.fade {
  opacity: 0;
}

/* media */
@media (min-width: 768px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .grid .item img{
    width: 60px;
  }
}
posted @ 2022-03-27 18:28  会前端的洋  阅读(34)  评论(0编辑  收藏  举报