响应式布局 媒体查询 弹性盒子 grid布局

媒体查询   弹性盒子

<!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 type="text/css">
        .div {
            display: flex;
            width: 100%;
        }
        
        .div div {
            width: 200px;
            height: 100px;
            background: red;
        }
        
        @media screen and (max-width:768px) {
            .div {
                flex-direction: column;
            }
        }
    </style>
</head>

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

</html>

@media screen and (max-width:768px) {

            .div {

                flex-direction: column;

            }

        }

and 后面与括号后面一定要记得加空格分开

 max-width:768px  屏幕最大是 768px

 min-width: 1000px 屏幕最小是 1000px

 ​

给父元素的来添加属性  来控制盒子的位置和排列方式

order 用来控制弹性盒子的顺序 值越小越靠前 默认值为0

flex-wrap :wrap 换行 

wrap-reverse  

<!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 type="text/css">
        .box {
            display: flex;
            /* 默认无效果 */
            flex-wrap: nowrap;
            /* 换行 */
            flex-wrap: wrap;
            /* 换行   第二行在上方 */
            /* flex-wrap: wrap-reverse; */
        }
        
        .box div {
            width: 200px;
            height: 200px;
            background: red;
            margin-right: 20px;
        }
    </style>
</head>

<body>
    <div>
        <div class="box">
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
            <div>6</div>
            <div>7</div>
            <div>8</div>
            <div>9</div>
            <div>10</div>
            <div>J</div>
            <div>Q</div>
            <div>K</div>
        </div>
    </div>
</body>

</html>

flex-wrap: nowrap;  /* 换行 */

/* 换行   第二行在上方 */ flex-wrap: wrap-reverse; 

<!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 type="text/css">
        .box {
            display: flex;
            /* 默认无效果 */
            /* 左 */
            /* justify-content: flex-start; */
            /* 右 */
            /* justify-content: flex-end; */
            /* 居中 */
            /* justify-content: center; */
            /* 中间平分 */
            /* justify-content: space-around; */
            /* 两端对齐 */
            /* justify-content: space-between; */
        }
        
        .box div {
            width: 200px;
            height: 200px;
            background: red;
            margin-right: 20px;
        }
    </style>
</head>

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

        </div>
    </div>
</body>

</html>

 /* 左 *//* justify-content: flex-start; */

/* 右 */ /* justify-content: flex-end; */           

/* 居中 */ /* justify-content: center; */           

 

/* 中间平分 *//* justify-content: space-around; */           

 

/* 两端对齐 */

            /* justify-content: space-between; */

<!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 type="text/css">
        .box {
            width: 900px;
            height: 400px;
            border: 1px solid red;
            display: flex;
            /* 上面 */
            /* align-items: flex-start; */
            /* 下面 */
            /* align-items: flex-end; */
            /* 中间 */
            /* align-items: center; */
            /* 拉伸 */
            align-items: stretch;
        }
        
        .box div {
            width: 200px;
            /* height: 200px; */
            background: red;
            margin-right: 20px;
        }
    </style>
</head>

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

        </div>
    </div>
</body>

</html>

 /* 下面 */align-items: flex-end;       

/* 上面 */  align-items: flex-start;

    /* 中间 */  align-items: center;   

/* 拉伸 */ align-items: stretch;

 

<!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>
    <link rel="stylesheet" href="练习1.css">
</head>

<body>
    <div class="box">
        <div class="div_1">
            <header>
                <ul>
                    <li>手机</li>
                    <li>查看更多<span>></span></li>
                </ul>
            </header>
            <section>
                <div>
                    <img src="0726img/left.jpg" alt="">
                </div>
                <div>
                    <ul>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                    </ul>
                </div>
                <div>
                    <ul>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                    </ul>
                </div>
                <div>
                    <ul>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                    </ul>
                </div>
                <div>
                    <ul>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                        <li>
                            <img src="0726img/1.png" alt="">
                            <p>Xiaomi 12S Ultra</p>
                            <p>这真徕卡 | 专业徕卡映像</p>
                            <p>5999元起</p>
                        </li>
                    </ul>
                </div>
            </section>
        </div>
    </div>
</body>

</html>
* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
}

.box .div_1 {
  margin: 0 auto;
  width: 1200px;
  height: 620px;
  border: 1px solid red;
}
.box .div_1 header {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 40px auto;
}
.box .div_1 header ul {
  border: 1px solid blue;
  grid-column-start: 1;
  display: flex;
  justify-content: space-between;
}
.box .div_1 header ul li {
  line-height: 40px;
}
.box .div_1 section {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows: 580px auto;
}
.box .div_1 section div:nth-child(1) img {
  width: 300px;
  height: 580px;
}
.box .div_1 section div:nth-child(2) ul li {
  margin-bottom: 10px;
}
.box .div_1 section div:nth-child(2) ul li img {
  width: 200px;
  height: 200px;
}
.box .div_1 section div:nth-child(2) ul li p {
  text-align: center;
}
.box .div_1 section div:nth-child(2) ul li p:nth-child(2) {
  font-size: 20px;
}
.box .div_1 section div:nth-child(2) ul li p:nth-child(4) {
  font-size: 20px;
  color: red;
}
.box .div_1 section div:nth-child(3) ul li img {
  width: 200px;
  height: 200px;
}
.box .div_1 section div:nth-child(3) ul li p {
  text-align: center;
}
.box .div_1 section div:nth-child(3) ul li p:nth-child(2) {
  font-size: 20px;
}
.box .div_1 section div:nth-child(3) ul li p:nth-child(4) {
  font-size: 20px;
  color: red;
}
.box .div_1 section div:nth-child(4) ul li img {
  width: 200px;
  height: 200px;
}
.box .div_1 section div:nth-child(4) ul li p {
  text-align: center;
}
.box .div_1 section div:nth-child(4) ul li p:nth-child(2) {
  font-size: 20px;
}
.box .div_1 section div:nth-child(4) ul li p:nth-child(4) {
  font-size: 20px;
  color: red;
}
.box .div_1 section div:nth-child(5) ul li img {
  width: 200px;
  height: 200px;
}
.box .div_1 section div:nth-child(5) ul li p {
  text-align: center;
}
.box .div_1 section div:nth-child(5) ul li p:nth-child(2) {
  font-size: 20px;
}
.box .div_1 section div:nth-child(5) ul li p:nth-child(4) {
  font-size: 20px;
  color: red;
}/*# sourceMappingURL=练习1.css.map */

grid-template-columns: 1fr 1fr 1fr 1fr 1fr;   分为五列

grid-template-rows: 580px auto;  最上面580px 下面自适应

grid-column-start: 1;  从第几列(从左边的单元格线)开始数

grid-column-end: 2;    到第几列(到最右边的第几个单元格线)结束

grid-row-start:  从第几行开始(最上面单元格 的单元格线开始数)

grid-row-end:从第几行开始(最下面的单元格先结束)

<main>
        <div>手机</div>
        <div><a href="#">查看更多</a></div>
        <div>left</div>
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
        <div>6</div>
        <div>7</div>
        <div>8</div>
    </main>
<style type="text/css">
        main{
            width: 2000px;
            overflow: auto;
            display: grid;
            grid-template-columns: repeat(5,200px);
            grid-template-rows: 50px 400px 400px;
            row-gap: 10px;
            column-gap: 10px;
        }
        main div{
            border: 1px solid red;
        }
        main div:nth-child(2){
            grid-column-start: 2;
            grid-column-end: 6;
            text-align: right;
        }
        main div:nth-child(3){
            grid-column-start: 1;
            grid-column-end: 2;
            grid-row-start: 2;
            grid-row-end: 4;
            border: 1px solid black;
        }
    <style>
<!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 type="text/css">
        .box {
            width: 1000px;
            margin: 0 auto;
            display: grid;
            grid-template-columns: repeat(4, 250px);
            grid-template-rows: repeat(4, 150px);
        }
        
        .box div {
            border: 1px solid red;
        }
        
        .box div:nth-child(1) {
            grid-column-start: 1;
            grid-column-end: 1;
            grid-row: 1/3;
        }
        
        .box div:nth-child(3) {
            /* grid-column-start: 1; */
            /* grid-column-end: 1; */
            grid-column: 3/4;
            grid-row: 1/3;
        }
        
        .box div:nth-child(7) {
            /* grid-column-start: 1; */
            /* grid-column-end: 1; */
            grid-column: 1/5;
            grid-row: 3/4;
        }
        
        .box div:nth-child(8) {
            /* grid-column-start: 1; */
            /* grid-column-end: 1; */
            grid-column: 2/3;
            grid-row: 3/4;
        }
    </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>7</div>
        <div>8</div>
    </div>
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值