前端flex布局属性及使用

flex布局

容器的6个属性

属性名 说明
flex-direction: row || row-reverse || column || column-reverse 主轴方向
justify-content: flex-start || flex-end || center || space-around || space-between 内容在主轴上的对齐方式
flex-wrap: nowrap || wrap 是否换行
flex-flow: || flex-direction和justify-content属性的缩写
align-items: stretch || flex-start || flex-end || center || baseline 内容在交叉轴上的对齐方式(单行有效)
align-content: stretch || flex-start || flex-end || space-around|| space-between 内容在交叉轴上的对齐方式(多行有效)

项目的3个属性

属性名 说明
flex: 1 || 2 || 3 || … 项目在剩余空间上所占空间的比例
order: … || -1 || 0 || 1 || … 项目在主轴上的排列顺序(值越小越靠前)
align-self: auto || flex-start || flex-end || center || baseline || stretch 单个项目在交叉轴上的对齐方式

使用flex布局绘制骰子


<html lang="ch">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>利用flex布局绘制骰子title>
    <style>
        .container {
      
            display: flex;
            flex-wrap: wrap;
        }

        .box {
      
            display: flex;
            width: 300px;
            height: 300px;
            background-color: pink;
            margin: 20px;
        }

        .point {
      
            width: 25%;
            height: 25%;
            background-color: black;
            border-radius: 50%;
        }

        .box1 {
      
            justify-content: center;
            align-items: center;
        }

        .box2 {
      
            justify-content: space-around;
            flex-direction: column;
            align-items: center;
        }

        .box3 {
      
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
        }

        .box3 div:nth-child(1) {
      
            align-self: flex-start;
        }

        .box3 div:nth-child(3) {
      
            align-self: flex-end;
        }

        .box4 {
      
            flex-direction: column;
        }

        .box44 {
      
            flex: 1;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }

        .point4 {
      
            width: 75px;
            height: 75px;
            background-color: black;
            border-radius: 50%;
        }

        .box5 {
      
            flex-direction: column;
        }

        .box55 {
      
            flex: 1;
            display: flex;
        }

        .box55:nth-child(2n-1) {
      
            justify-content: space-around;
            align-items: center;
        }

        .box55:nth-child(2) {
      
            justify-content: center;
            align-items: center;
        }

        .point5 {
      
            width: 75px;
            height: 75px;
            background-color: black;
            border-radius: 50%;
        }

        .box6 {
      
            flex-direction: column;
        }

        .box66 {
      
            flex: 1;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }

        .point6 {
      
            width: 75px;
            height: 75px;
            background-color: black;
            border-radius: 50%;
        }
    style>
head>

<body>
    <div class="container">
        <div class="box1 box">
            <div class="point">div>
        div>

        <div class="box box2">
            <div class="point">div>
            <div class="point">div>
        div>

        <div class="box box3">
            <div class="point">div>
            <div class="point">div>
            <div class="point">div>
        div>

        <div class="box box4">
            <div class="box44">
                <div class="point4">div>
                <div class="point4">div>
            div>
            <div class="box44">
                <div class="point4">div>
                <div class="point4">div>
            div>
        div>

        <div class="box box5">
            <div class="box55">
                <div class="point5">div>
                <div class="point5">div>
            div>
            <div class="box55">
                <div class="point5">div>
            div>
            <div class="box55">
                <div class="point5">div>
                <div class="point5">div>
            div>
        div>

        <div class="box box6">
            <div class="box66">
                <div class="point6">div>
                <div class="point6">div>
            div>
            <div class="box66">
                <div class="point6">div>
                <div class="point6">div>
            div>
            <div class="box66">
                <div class="point6">div>
                <div class="point6">div>
            div>
        div>
    div>
body>

html>

你可能感兴趣的:(学习笔记,html,flex)