Day_6 #7

Open
opened 2026-09-11 18:27:58 +08:00 by pjc · 6 comments
Owner
No description provided.

AI页面说明

1. 导航栏是怎么两端对齐的?

导航栏父容器用了 display: flex,让 Logo 和菜单排成一行。

关键属性是 justify-content: space-between,它把第一个子元素(Logo)推到最左边,最后一个子元素(菜单)推到最右边,实现两端对齐。

同时用 align-items: center 让 Logo 和菜单在垂直方向居中。

用到的选择器:.navbar。
用到的属性:display: flex、justify-content: space-between、align-items: center。

2. 卡片区是用什么布局排成一行的?

卡片容器用了 display: flex 和 flex-wrap: wrap,默认横向排列,空间不够时自动换行。

每张卡片设置 flex: 1 1 250px,表示可以放大、可以缩小,基础宽度 250px,这样三张卡片能平分一行。

卡片之间用 gap: 20px 拉开间距。

媒体查询 @media (min-width: 768px) 里把 flex-wrap 改成 nowrap,屏幕 ≥768px 时强制不换行,三张卡片就在同一行等分宽度。

用到的选择器:.card-container、.card、@media。
用到的属性:display: flex、flex-wrap、gap、flex、@media (min-width: 768px)。

3. 还有哪些 CSS 知识点在起作用?

  • viewport meta:让手机按真实屏幕宽度渲染,媒体查询才能正确触发。
  • box-sizing: border-box:让 padding 和 border 算在宽度内,布局更可控。
  • border-radius:卡片圆角。
  • box-shadow:卡片阴影,增加层次感。
  • text-decoration: none:去掉链接下划线。

总结

这个页面主要用 Flexbox 完成导航栏和卡片区布局,配合媒体查询做响应式。导航栏靠 space-between 两端对齐,卡片区靠 flex 和 flex-wrap 自动排列,宽屏时通过 nowrap 保持一行。

profile.html:

<!doctype html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>我的个人主页</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        font-family: sans-serif;
        background-color: #f5f7fa;
      }

      /* 导航栏 */
      .navbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 30px;
        background-color: #2c3e50;
        color: white;
      }

      .logo {
        font-size: 24px;
        font-weight: bold;
      }

      .nav-links {
        display: flex;
        gap: 20px;
        list-style: none;
      }

      .nav-links a {
        color: white;
        text-decoration: none;
      }

      /* 卡片区 */
      .card-section {
        padding: 40px 30px;
      }

      .card-container {
        display: flex;
        flex-wrap: wrap;
        gap: 20px;
      }

      .card {
        background-color: white;
        border-radius: 10px;
        padding: 20px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        flex: 1 1 250px;
      }

      /* 响应式:小屏一列,大屏一行 */
      @media (min-width: 768px) {
        .card-container {
          flex-wrap: nowrap;
        }
      }
    </style>
  </head>
  <body>
    <nav class="navbar">
      <div class="logo">我的主页</div>
      <ul class="nav-links">
        <li><a href="#">首页</a></li>
        <li><a href="#">关于我</a></li>
        <li><a href="#">联系</a></li>
      </ul>
    </nav>

    <section class="card-section">
      <div class="card-container">
        <div class="card">
          <h2>关于我</h2>
          <p>我是 pjc 头号粉丝,正在学习前端。</p>
        </div>
        <div class="card">
          <h2>我的技能</h2>
          <p>HTML、CSS、Flexbox 布局。</p>
        </div>
        <div class="card">
          <h2>联系我</h2>
          <p>邮箱:example@example.com</p>
        </div>
      </div>
    </section>
  </body>
</html>
# AI页面说明 ## 1. 导航栏是怎么两端对齐的? 导航栏父容器用了 `display: flex`,让 Logo 和菜单排成一行。 关键属性是 `justify-content: space-between`,它把第一个子元素(Logo)推到最左边,最后一个子元素(菜单)推到最右边,实现两端对齐。 同时用 `align-items: center` 让 Logo 和菜单在垂直方向居中。 用到的选择器:`.navbar`。 用到的属性:`display: flex`、`justify-content: space-between`、`align-items: center`。 ## 2. 卡片区是用什么布局排成一行的? 卡片容器用了 `display: flex` 和 `flex-wrap: wrap`,默认横向排列,空间不够时自动换行。 每张卡片设置 `flex: 1 1 250px`,表示可以放大、可以缩小,基础宽度 250px,这样三张卡片能平分一行。 卡片之间用 `gap: 20px` 拉开间距。 媒体查询 `@media (min-width: 768px)` 里把 `flex-wrap` 改成 `nowrap`,屏幕 ≥768px 时强制不换行,三张卡片就在同一行等分宽度。 用到的选择器:`.card-container`、`.card`、`@media`。 用到的属性:`display: flex`、`flex-wrap`、`gap`、`flex`、`@media (min-width: 768px)`。 ## 3. 还有哪些 CSS 知识点在起作用? - viewport meta:让手机按真实屏幕宽度渲染,媒体查询才能正确触发。 - `box-sizing: border-box`:让 padding 和 border 算在宽度内,布局更可控。 - `border-radius`:卡片圆角。 - `box-shadow`:卡片阴影,增加层次感。 - `text-decoration: none`:去掉链接下划线。 ## 总结 这个页面主要用 Flexbox 完成导航栏和卡片区布局,配合媒体查询做响应式。导航栏靠 `space-between` 两端对齐,卡片区靠 `flex` 和 `flex-wrap` 自动排列,宽屏时通过 `nowrap` 保持一行。 **profile.html:** ```html <!doctype html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>我的个人主页</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: sans-serif; background-color: #f5f7fa; } /* 导航栏 */ .navbar { display: flex; justify-content: space-between; align-items: center; padding: 15px 30px; background-color: #2c3e50; color: white; } .logo { font-size: 24px; font-weight: bold; } .nav-links { display: flex; gap: 20px; list-style: none; } .nav-links a { color: white; text-decoration: none; } /* 卡片区 */ .card-section { padding: 40px 30px; } .card-container { display: flex; flex-wrap: wrap; gap: 20px; } .card { background-color: white; border-radius: 10px; padding: 20px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); flex: 1 1 250px; } /* 响应式:小屏一列,大屏一行 */ @media (min-width: 768px) { .card-container { flex-wrap: nowrap; } } </style> </head> <body> <nav class="navbar"> <div class="logo">我的主页</div> <ul class="nav-links"> <li><a href="#">首页</a></li> <li><a href="#">关于我</a></li> <li><a href="#">联系</a></li> </ul> </nav> <section class="card-section"> <div class="card-container"> <div class="card"> <h2>关于我</h2> <p>我是 pjc 头号粉丝,正在学习前端。</p> </div> <div class="card"> <h2>我的技能</h2> <p>HTML、CSS、Flexbox 布局。</p> </div> <div class="card"> <h2>联系我</h2> <p>邮箱:example@example.com</p> </div> </div> </section> </body> </html> ```

加了 viewport,媒体查询能切换布局

<html lang="zh"> <head> <style> .cards { display: flex; flex-direction: column; gap: 20px; } .card { border: 1px solid #000; padding: 20px; display: flex; border-radius: 8px; } @media (min-width: 768px) { .cards{ justify-content: space-between;
            flex-direction: row;
        }
        .card {
            flex: 1; 
        }
    }

</style>
</head>
算了吧
没结果的
不会响应的
</html>
加了 viewport,媒体查询能切换布局 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>念念不忘,必有回响</title> <style> .cards { display: flex; flex-direction: column; gap: 20px; } .card { border: 1px solid #000; padding: 20px; display: flex; border-radius: 8px; } @media (min-width: 768px) { .cards{ justify-content: space-between; flex-direction: row; } .card { flex: 1; } } </style> </head> <div class="cards"> <div class="card">算了吧</div> <div class="card">没结果的</div> <div class="card">不会响应的</div> </div> </html>

看懂了ai写的页面

<!DOCTYPE html>
<html>
    <head>
        <style>
            .boxes
            {
                display: flex;
                flex-direction:row;
                justify-content: center;
                gap: 20px;

            }
            .box
            {
                background-color: blueviolet;
                width: 80px;
                height: 80px;
            }
            @media (max-width:768px){
                .box{
                    background-color: blue;
                    flex: 1;
                }
                .boxes{
                    flex-direction: column;
                }

            }
        </style>
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
    </head>
    <body>
        <div class="boxes">
                    <div class="box">desktop:💜;mobile:💙</div><div class="box">desktop:💜;mobile:💙</div><div class="box">desktop:💜;mobile:💙</div>

        </div>
    </body>
</html>
看懂了ai写的页面 ```html <!DOCTYPE html> <html> <head> <style> .boxes { display: flex; flex-direction:row; justify-content: center; gap: 20px; } .box { background-color: blueviolet; width: 80px; height: 80px; } @media (max-width:768px){ .box{ background-color: blue; flex: 1; } .boxes{ flex-direction: column; } } </style> <meta name="viewport" content="width=device-width,initial-scale=1.0"> </head> <body> <div class="boxes"> <div class="box">desktop:💜;mobile:💙</div><div class="box">desktop:💜;mobile:💙</div><div class="box">desktop:💜;mobile:💙</div> </div> </body> </html> ```

1导航栏是怎么两端对齐的?
用display: flex justify-content: space-between;两端对齐
2卡片区是用什么布局排成一行的?
媒体里面用flex-direction: row; 保证长度足够时按行排列
3AI 页面里至少 3 处用到的 CSS 知识点:
box-shadow 给容器设置阴影,更真实好看。
transition:让动画变化有过度更平滑
object-fit:设置图片在容器中怎么填充

1导航栏是怎么两端对齐的? 用display: flex justify-content: space-between;两端对齐 2卡片区是用什么布局排成一行的? 媒体里面用flex-direction: row; 保证长度足够时按行排列 3AI 页面里至少 3 处用到的 CSS 知识点: box-shadow 给容器设置阴影,更真实好看。 transition:让动画变化有过度更平滑 object-fit:设置图片在容器中怎么填充

两端对齐通过display: flex; 和justify-content: space-between;实现。
排成一行默认用 flex-direction: column;排成一列,当屏幕宽度 ≥ 768px 时,用@media把它改成 flex-direction: row;排成一行
类选择器.navbar、.card-container
属性display: flex:开启弹性布局。justify-content: space-between:两端对齐。flex-direction:控制横排还是竖排。@media (min-width: 768px):媒体查询,屏幕够宽时才应用横排规则。viewport meta:让手机屏幕按真实宽度显示,媒体查询才准确。
image.pngimage.png

两端对齐通过display: flex; 和justify-content: space-between;实现。 排成一行默认用 flex-direction: column;排成一列,当屏幕宽度 ≥ 768px 时,用@media把它改成 flex-direction: row;排成一行 类选择器.navbar、.card-container 属性display: flex:开启弹性布局。justify-content: space-between:两端对齐。flex-direction:控制横排还是竖排。@media (min-width: 768px):媒体查询,屏幕够宽时才应用横排规则。viewport meta:让手机屏幕按真实宽度显示,媒体查询才准确。 ![image.png](/attachments/32006110-eab2-4467-86ac-c34100547553)![image.png](/attachments/cc7142ed-6945-49ff-bb94-8a8a5a970dbd)
298 KiB
110 KiB

都懂了

`<!doctype html>

<html lang="zh-CN"> <head> <style> * { margin: 0; padding: 0; box-sizing: border-box; } /* 导航栏 */ nav { background: #222; color: white; padding: 16px 24px; /* flex实现两端对齐 */ display: flex; justify-content: space-between; align-items: center; } .nav-links a { color: #fff; text-decoration: none; margin-left: 16px; }
  .container {
    padding: 30px;
  }
  .card-wrap {
    display: flex;
    /* 默认手机:卡片纵向排列 1列 */
    flex-direction: column;
    gap: 20px;
  }
  .card {
    border: 1px solid #ccc;
    padding: 20px;
    border-radius: 8px;
  }

  /* ✅ 媒体查询:屏幕 >=768px(电脑大屏)生效 */
  @media (min-width: 768px) {
    .card-wrap {
      flex-direction: row; /* 大屏卡片横向排成一行 */
    }
  }
  .logo {
    color: red;
  }
</style>
</head>
我的主页
<div class="container">
  <h2>我的卡片</h2>
  <div class="card-wrap">
    <div class="card">卡片1</div>
    <div class="card">卡片2</div>
    <div class="card">卡片3</div>
  </div>
</div>
</html> `![image.png](/attachments/59a7852e-3d6f-48fd-ae8c-d1510729823a) ![image.png](/attachments/2351d6a7-1ef0-4ca5-8eb2-d4e1561357b0)
都懂了 `<!doctype html> <html lang="zh-CN"> <head> <meta charset="UTF-8" /> <!-- ✅ viewport 必加,移动端适配 --> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>个人主页</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } /* 导航栏 */ nav { background: #222; color: white; padding: 16px 24px; /* flex实现两端对齐 */ display: flex; justify-content: space-between; align-items: center; } .nav-links a { color: #fff; text-decoration: none; margin-left: 16px; } .container { padding: 30px; } .card-wrap { display: flex; /* 默认手机:卡片纵向排列 1列 */ flex-direction: column; gap: 20px; } .card { border: 1px solid #ccc; padding: 20px; border-radius: 8px; } /* ✅ 媒体查询:屏幕 >=768px(电脑大屏)生效 */ @media (min-width: 768px) { .card-wrap { flex-direction: row; /* 大屏卡片横向排成一行 */ } } .logo { color: red; } </style> </head> <body> <!-- 导航栏 --> <nav> <div class="logo">我的主页</div> <div class="nav-links"> <a href="#">首页</a> <a href="#">关于</a> <a href="#">作品</a> </div> </nav> <div class="container"> <h2>我的卡片</h2> <div class="card-wrap"> <div class="card">卡片1</div> <div class="card">卡片2</div> <div class="card">卡片3</div> </div> </div> </body> </html> `![image.png](/attachments/59a7852e-3d6f-48fd-ae8c-d1510729823a) ![image.png](/attachments/2351d6a7-1ef0-4ca5-8eb2-d4e1561357b0)
136 KiB
159 KiB
Sign in to join this conversation.