flexbox的學習,display:flex display:box 淘寶觸屏版、餓了麼網布局分析分析

 

Flex 佈局教程:語法篇

http://www.ruanyifeng.com/blog/2015/07/flex-grammar.htmlcss

父:html

display:flex;web

      父屬性設置瀏覽器

  • flex-direction: row | row-reverse | column | column-reverse;
  • flex-wrap:nowrap | wrap | wrap-reverse;
  • flex-flow: <flex-direction> || <flex-wrap>;
  • justify-content:flex-start | flex-end | center | space-between | space-around;
  • align-items:flex-start | flex-end | center | baseline | stretch;
  • align-content:flex-start | flex-end | center | space-between | space-around | stretch;

     子屬性設置佈局

  • order:number 越小越前
  • flex-grow :0 無變化  剩餘長度按比例分配
  • flex-shrink:0 無變化   按比例縮小
  • flex-basis :auto /固定的值
  • flex:none [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
  • align-self:auto | flex-start | flex-end | center | baseline | stretch;
    子元素上下的對其方式

 

css display:box 新屬性 post

https://www.cnblogs.com/whiteMu/p/5378747.htmlflex

1、display:box;ui

  在元素上設置該屬性,可以使其子代排列在同一水平上,相似display:inline-block;。flexbox

2、可在其子代設置以下屬性spa

  前提:使用以下屬性,必須在父代設置display:box;

  1.box-flex:number;

    1)佔父級元素寬度的number份

    2)若子元素設置固定寬度,則該子元素應用固定寬度,其餘未設置固定寬度的字元素將餘下的父級寬度(父級-已設置固定寬度的子代元素的總寬度按 number佔份數

    3)若子元素有margin值,則按餘下(父級寬度-子代固定總寬度-總margin值)寬度佔number份

  2.box-orient:horizontal/vertical

    在父級上設置該屬性,則子代按水平排列或豎直排列。

    注:全部主流瀏覽器不支持該屬性,必須加上前綴。

    1)horizontal  水平排列,子代總width=父級width。若父級固定寬度,則子代設置的width無效,子代會撐滿父級寬度。

    2)vertical  垂直排列,子代總height=父級height。若父級固定高度,則子代設置的height無效,子代會撐滿父級高度。

  3.box-direction:normal/reverse

    在父級上設置該屬性,確認子代的排列順序。

    1)normal  默認值,子代按html順序排列

    2)reverse  反序

  4.box-align:start/end/center/stretch

    在父級設置,子代的垂直對齊方式。

    1)start  垂直頂部對齊

    2)end 垂直底部對齊

    3)center 垂直居中對齊

    4)stretch 拉伸子代的高度,與父級設置的高度一致。子代height無效。

  5.box-pack:start/end/center

    在父級設置,子代的水平對齊方式。

    1)start  水平左對齊

    2)end  水平右對齊

    3)center  水平居中對齊 

 

display:-ms-flexbox       https://msdn.microsoft.com/en-us/library/hh673531(v=vs.85).aspx

-ms-flex-direction: row|row-reverse|column|column-reverse

-ms-flex-align:start|end|center|stretch|baseline    =flex的align-items

-ms-flex-pack:start|end|cener|justify           =flex的justify-content

-ms-flex-wrap:nowrap|wrap|wrap-reverse

-ms-flex:<positive-flex> <negative-flex> <preferred-size>   =flex的flex

-ms-flex-order:  =flex的order

 

一、實現淘寶中這些條目的佈局

 

相似實現的代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin:0;padding:0;
        }
        html{font-size:32px;}
        .item-content{
            display: -webkit-box;
            display: -moz-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -moz-box-orient: vertical;
            -moz-box-direction: normal;
            -webkit-flex-direction: column;
            -ms-flex-direction: column;
            flex-direction: column;
            box-sizing: border-box;
            line-height: 0;
            width: 10rem;
            height: 4.594rem;
            background-color: rgb(255, 255, 255);
            margin:0 auto;
        }
        .item-small{
            display: -webkit-box;
            display: -moz-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: horizontal;
            -webkit-box-direction: normal;
            -moz-box-orient: horizontal;
            -moz-box-direction: normal;
            -webkit-flex-direction: row;
            -ms-flex-direction: row;
            flex-direction: row;
            box-sizing: border-box;
            line-height: 0;
            width:10rem;
            height:2rem;
            background-color: green;
        }
        .item{
            width:2rem;
            height:2rem;
            box-sizing: border-box;
            border:10px solid #fff;
        }
        .item:nth-child(odd){
            background-color:red;
        }
        .item:nth-child(even){
            background-color:green;
        }
    </style>
</head>
<body>
<div class="item-content">
    <div class="item-small">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
    <div class="item-small">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
</div>
</body>
</html>

 

  

餓了麼的商家列表

 

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        .item-content{
            width:100%;
            display: -webkit-flex;
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-justify-content: flex-start;
            -webkit-box-pack: start;
            -ms-flex-pack: start;
            justify-content: flex-start;
            -webkit-align-items: stretch;
            -webkit-box-align: stretch;
            -ms-flex-align: stretch;
            align-items: stretch;
        }
        .fixedwidthitem{
            position: relative;
            -webkit-flex: 0 0 auto;
            /* -webkit-box-flex: 1; */
            -ms-flex: none;
            /* flex: none; */
        }
        .imgcontent{
            width:64px;
            height:64px;
            background-color:red;
        }
        .flexwidth{
            -webkit-flex-grow: 1;
            -webkit-box-flex: 1;
            -ms-flex-positive: 1;
            flex-grow: 1;
            -webkit-flex-direction: column;
            -webkit-box-orient: vertical;
            -webkit-box-direction: normal;
            -ms-flex-direction: column;
            flex-direction: column;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            display: -webkit-flex;
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-justify-content: space-between;
            -webkit-box-pack: justify;
            -ms-flex-pack: justify;
            justify-content: space-between;
             overflow: hidden;
        }
        .index-line_2-iYR1A{
            display: -webkit-flex;
            display: -webkit-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-justify-content: space-between;
            -webkit-box-pack: justify;
            -ms-flex-pack: justify;
            /* justify-content: space-between; */
            /* overflow: hidden; */
            -webkit-align-items: center;
            -webkit-box-align: center;
            -ms-flex-align: center;
            align-items: center;
        }

    </style>
</head>
<body>
<div class="item-content">
    <div class="fixedwidthitem">
        <div class="imgcontent"></div>
    </div>
    <div class="flexwidth">
        <div class="index-line_2-iYR1A">
            <h3>知味觀</h3>
            <span>11111</span>
        </div>
        <div class="index-line_2-iYR1A">
            <div>¥20起送</div>
            <span>37分鐘</span>
        </div>
        <div class="index-line_2-iYR1A">
            <span>口碑人氣好店</span>
        </div>
    </div>
</div>
</body>
</html>

 

實際效果: 

 

相關文章
相關標籤/搜索