HTML CSS第七次笔记

1 弹性盒子换行

1.1 实现重点

·使用justify-content: space-between;实现主轴对齐
·使用margin-bottom: 14px;实现小li上下间隙
·使用flex-wrap: wrap;实现弹性盒子换行

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* margin: 0 和 padding: 0 用于清除所有元素的默认外边距和内边距 */
    /* box-sizing: border-box 设置盒模型的计算方式,使得元素的宽度和高度包含内边距和边框 */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    .mi {
      /* 父控子(布局) */
      display: flex;
      /* 主轴分布(两个子盒子贴两边) */
      justify-content: space-between;
      width: 1226px;
      height: 614px;
      /* background-color: pink; */
      margin: 100px auto;
    }

    .left {
      width: 234px;
      height: 614px;
      background-color: skyblue;
    }

    .right {
      width: 978px;
      height: 614px;
      background-color: purple;
    }

    .right ul {
      display: flex;
      /* 弹性盒子换行 */
      flex-wrap: wrap;
      justify-content: space-between;
      
    }

    .right li {
      width: 234px;
      height: 300px;
      background-color: orange;
      /* 去除小li的小点 */
      list-style: none;
      margin-bottom: 14px;
    }
  </style>
</head>

<body>
  <div class="mi">
    <div class="left"></div>
    <div class="right">
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
      </ul>
    </div>
  </div>
</body>

</html>

结果:

2 多行主轴对齐(align-content)

align-content与align-items(测轴对齐)的区别是前者是多行对齐,后者是单行对齐

2.1 实现重点

·使用justify-content: space-between;实现左右没缝隙(主轴对齐)
·使用align-content: space-between;实现上下没缝隙(测轴对齐)

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      display: flex;
      flex-wrap: wrap;
      /* 左右没缝隙(主轴对齐) */
      justify-content: space-between;
      /* 上下没缝隙(测轴对齐) */
      align-content: space-between;
      width: 1000px;
      height: 500px;
      border: 1px solid #000;
      margin: 100px auto;
    }

    .box div {
      width: 300px;
      height: 200px;
      background-color: pink;
    }
  </style>
</head>

<body>
  <div class="box">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>

  </div>
</body>

</html>

结果:

3 某个弹性盒子测轴对齐方式(align-self)

3.1 实现重点

·使用align-self实现只移动一个子盒子
·再在css中使用.box:nth-child(n)选中某个盒子给他添加样式

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      /* 只让其中一个移动 */

      width: 600px;
      height: 600px;
      border: 1px solid #000;
      margin: 100px auto;
    }

    .box div {
      width: 100px;
      height: 100px;
      background-color: pink;
      border-radius: 50%;
    }

    .box div:nth-child(2) {
      /* 只移动某一个盒子 */
      align-self: center;
    }

    .box div:nth-child(3) {
      align-self: flex-end;
    }
  </style>
</head>

<body>
  <div class="box">
    <div></div>
    <div></div>
    <div></div>
  </div>
</body>

</html>

结果:

4 修改主轴方向(flex-direction)

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      display: flex;
      /* 默认主轴是横向排列(row),此时要更改主轴方向 */
      flex-direction: column;
      width: 300px;
      height: 300px;
      border: 1px solid #000;
      /* margin: 100px auto; */
      justify-content: center;
      align-items: center;

    }

    .box div {
      width: 100px;
      height: 100px;
      background-color: pink;
    }
  </style>
</head>

<body>
  <div class="box">
    <div>1</div>
    <div>2</div>
  </div>
</body>

</html>

结果:

5 弹性伸缩比(align-content)

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      display: flex;
      /* 宽度占浏览器的百分之八十 */
      width: 80%;
      height: 150px;
      border: 1px solid #000;
      margin: 50px auto;
    }

    .box div {
      background-color: pink;
      /* 给子盒子添加 */
      /* 子盒子平分父盒子的宽度  写∏就代表分几份*/
      flex: 1;
    }

    .box div:nth-child(2) {
      background-color: purple;
      flex: 2;
      margin: 0 10px;
    }
  </style>
</head>

<body>
  <div class="box">
    <div>1</div>
    <div>2</div>
    <div>3</div>
  </div>

</body>

</html>

结果:

相关推荐
灿灿121385 分钟前
CSS 文字浮雕效果:巧用 text-shadow 实现 3D 立体文字
前端·css
烛阴23 分钟前
Babel 完全上手指南:从零开始解锁现代 JavaScript 开发的超能力!
前端·javascript
AntBlack41 分钟前
拖了五个月 ,不当韭菜体验版算是正式发布了
前端·后端·python
315356691343 分钟前
一个简单的脚本,让pdf开启夜间模式
前端·后端
尘心cx1 小时前
前端-CSS-day1
前端·css
知否技术1 小时前
前端常说的 SCSS是个啥玩意?一篇文章给你讲的明明白白!
前端·scss
幼儿园技术家1 小时前
Uniapp简易使用canvas绘制分享海报
前端
开开心心就好2 小时前
免费PDF处理软件,支持多种操作
运维·服务器·前端·spring boot·智能手机·pdf·电脑
全宝2 小时前
🎨前端实现文字渐变的三种方式
前端·javascript·css
没有钱的钱仔2 小时前
STM32低功耗模式全面指南
css·stm32·css3