美文网首页
CSS3 伸缩布局

CSS3 伸缩布局

作者: Merbng | 来源:发表于2019-03-24 22:17 被阅读0次
  • 主轴:
    Flex容器的主轴主要是用来配置Flex项目,默认是水平方向。
  • 侧轴:
    与主轴垂直的轴称作侧轴,默认是垂直方向的。
  • 方向:
    默认主轴从左往右,侧轴从上到下。
    主轴和侧轴并不是固定不变的,通过flex-direction可以互换

对浏览器的支持不一致

属性详解

1.min-width 最小宽度 、max-width 最大宽度
2.flex-direction 调整主轴方向(默认为水平方向)
flex-direction:column(垂直排列)
flex-direction:row(水平排列)

<!DOCTYPE html>
<html lang="zh">
    <head>
        <title></title>
    </head>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        body {
            min-width: 320px;
            max-width: 540px;
            background-color: white;
            margin: 0 auto;
        }

        header {
            height: 108px;
        }

        header img {
            height: 100%;
            width: auto;
        }

        nav {
            border: 1px solid #ccc;
            padding: 4px;
        }

        .row {
            height: 90px;
            display: flex;
            border-radius: 5px;
            overflow: hidden;
            margin-bottom: 5px;
        }

        .row div {
            height: 100%;
            flex: 1;
            background-color: #ff687a;
            border-right: 1px solid white;
        }

        .row div:nth-child(3) {
            border-right: 0;
        }

        .row div a {
            display: block;
        }

        .row33 {
            display: flex;
            flex-direction: column;
        }

        .row33 a {
            flex: 1;
            text-align: center;
            line-height: 45px;
        }

        .row33 a:first-child {
            border-bottom: 1px solid white;
        }

        nav a {
            text-decoration: none;
            color: white;
            font-size: 14px;
            text-shadow: 0 2px 1px rgba(0, 0, 0, .2);
        }

        .row em {
            display: block;
            height: 45px;
            line-height: 45px;
            text-align: center;
            font-style: normal;
        }

        .row i {

            display: block;
            height: 43px;
            width: 43px;
            margin: -5px auto;
            background: url(images/ctrip.png) no-repeat 0 -127px;
            background-size: 104px auto;
            /* 浏览器前缀 */
            -webkit-background-size: 104px;
            -moz-background-size: 104px;
            -ms-background-size: 104px;
            -o-background-size: 104px;
            background-position: 0 -288px;
        }

        .row .icon-flight {
            background-position: 0 -124px;
        }
    </style>
    <body>
        <header>
            <img src="images/banner.jpg" alt="">
        </header>
        <nav>
            <div class="row">
                <div><a href="#">
                        <em>酒店</em>
                        <i class="icon-flight"></i>
                    </a>
                </div>
                <div class="row33">
                    <a href="#">海外酒店</a>
                    <a href="#">特价酒店</a>
                </div>
                <div class="row33">
                    <a href="#">团购</a>
                    <a href="#">民宿客栈</a>
                </div>
            </div>
            <div class="row">
                <div><a href="#">
                        <em>酒店</em>
                        <i></i>
                    </a>
                </div>
                <div class="row33">
                    <a href="#">海外酒店</a>
                    <a href="#">特价酒店</a>
                </div>
                <div class="row33">
                    <a href="#">团购</a>
                    <a href="#">民宿客栈</a>
                </div>
            </div>
            <div class="row">
                <div><a href="#">
                        <em>酒店</em>
                        <i></i>
                    </a>
                </div>
                <div class="row33">
                    <a href="#">海外酒店</a>
                    <a href="#">特价酒店</a>
                </div>
                <div class="row33">
                    <a href="#">团购</a>
                    <a href="#">民宿客栈</a>
                </div>
            </div>
            <div class="row">
                <div class="row33">
                    <a href="#">海外酒店</a>
                    <a href="#">特价酒店</a>
                    </a>
                </div>
                <div class="row33">
                    <a href="#">海外酒店</a>
                    <a href="#">特价酒店</a>
                </div>
                <div class="row33">
                    <a href="#">团购</a>
                    <a href="#">民宿客栈</a>
                </div>
            </div>
        </nav>
    </body>
</html>
  1. justify-content 调整主轴对齐(水平对齐)
    align-items 调整侧轴对齐(垂直对齐)
<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title></title>
        <style type="text/css">
            section {
                width: 80%;
                height: 150px;
                margin: 100px auto;
                /* 给父亲添加 伸缩布局 */
                display: flex;
                /* section 最小的宽度是500 */
                min-width: 500px;
                /*默认水平分布:row , 垂直分布
                 
                 reverse翻转
                 */
                flex-direction: row-reverse;
            }

            section div {
                height: 100%;

            }

            section div:nth-child(1) {
                background-color: pink;
                width: 200px;
            }

            section div:nth-child(2) {
                background-color: purple;
                flex: 2;
            }

            section div:nth-child(3) {
                background-color: red;
                flex: 1;
            }
        </style>
    </head>
    <body>
        <section>
            <div>1</div>
            <div>2</div>
            <div>3</div>
        </section>
    </body>
</html>

事例代码地址

相关文章

  • 第10章 布局样式相关-伸缩布局(Flexible Box)

    伸缩布局(一) CSS3引入了一种新的布局模式——Flexbox布局,即伸缩布局盒模型(Flexible Box)...

  • CSS3之Flexbox布局在ReactNative的应用

    CSS3为我们提供了一种可伸缩的灵活的web页面布局方式-flexbox布局,被成为弹性布局(或者伸缩布局)。相比...

  • CSS3伸缩布局

    CSS3伸缩布局 CSS3中的 flex 属性,在布局方面做了非常大的改进,使得我们对多个元素之间的布局排列变得十...

  • flex伸缩布局

    CSS3引入了一种新的布局模式——Flexbox布局,即伸缩布局盒模型(Flexible Box) Flexbox...

  • 学习CSS3伸缩布局盒模型Flex布局

    一、Flex 布局是什么? CSS3引入了一种新的布局模式——Flexbox布局,即伸缩盒模型布局(Flexibl...

  • flex布局那些事儿

    什么是FLEX CSS3引入了一种新的布局模式——Flexbox布局,即伸缩布局盒(Flexible Box)模型...

  • css3伸缩布局

    伸缩布局(CSS3) CSS3在布局方面做了非常大的改进,使得我们对块级元素的布局排列变得十分灵活,适应性非常强,...

  • 入坑 React Native 之FlexBox布局

    FlexBox布局也叫弹性盒子,弹性布局.是CSS3为我们提供了一种可伸缩的灵活的页面布局方式-flexbox布局...

  • CSS3 伸缩布局

    CSS3引入了一种新的布局模式——Flexbox布局,即伸缩布局盒模型(Flexible Box),用来提供一个更...

  • css3 伸缩布局

    伸缩布局 设置父元素为伸缩盒子, (直接父元素) 为什么伸缩盒子子元素在一行上显示?子元素是按照伸缩盒子主轴方向显...

网友评论

      本文标题:CSS3 伸缩布局

      本文链接:https://www.haomeiwen.com/subject/hxipvqtx.html