Flex for web mobile development (elastic box - Chapter 2 of Knowledge Points)

        

Step 1: Upper frame and div

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	
	<style>
	#bodys{
		width: 600px;
		height: 600px;
		background: wheat;
	}	
	
	
	.one{
		width: 100px;
		height: 100px;
		background-color: lawngreen;
	}
	
	
	.two{
		width: 100px;
		height: 100px;
		background-color: darkgoldenrod;
	}
	
	
	.three{
		width: 100px;
		height: 100px;
		background-color: darkmagenta;
	}
	</style>
	<body>
			<div id="bodys">
				<div class="one">
					
				</div>
				
				<div class="two">
					
				</div>
				
				<div class="three">
					
				</div>
			</div>
	</body>
</html>

        Step 2: Today let's get to know justify-content

 

<!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>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            width: 500px;
            height: 200px;
            margin: 20px;
            border: 2px solid black;
            /* 设为弹性盒子 */
            display: flex;
            
        }
        li{
            /* 去除默认样式 */
            list-style: none;
            width: 50px;
            border: 1px solid red;
            text-align: center;
            font-size: 20px;
        }
        ul:nth-of-type(1){
            /* 主轴开始对齐(默认值)*/
            justify-content: flex-start;
        }
        ul:nth-of-type(2){
            /* 主轴结束对齐 */
            justify-content: flex-end;
        }
        ul:nth-of-type(3){
            /* 主轴居中对齐 */
            justify-content:center;
        }
        ul:nth-of-type(4){
            /* 主轴两端对齐 */
            justify-content:space-between;
        }
        ul:nth-of-type(5){
            /* 2边间距和中间间距的比值是1:2 */
            justify-content:space-around;
        }
        ul:nth-of-type(6){
            /* 2边间距和中间间距的比值是1:1 */
            justify-content:space-evenly;
        }
    </style>
</head>
<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
</body>
</html>

 

Guess you like

Origin blog.csdn.net/tea_tea_/article/details/126162164