资讯专栏INFORMATION COLUMN

flex布局示例代码二

Forest10 / 1539人阅读

摘要:本次主要理解布局中元素的几个属性,今天理解第一个属性属性翻译成人话就是,元素按照定义的序号,顺序排列,序号小的在前面。数值越小,排列越靠前,默认为。

本次主要理解flex布局中元素的几个属性,今天理解第一个order属性

order属性翻译成人话就是,元素按照order定义的序号,顺序排列,序号小的在前面。

order:定义项目的排列顺序。数值越小,排列越靠前,默认为0。

https://developer.mozilla.org...

In the live example below I have added a focus style in order that as you tab from link to link you can see which is highlighted. If you change the order using flex-direction you can see how the tab order continues to follow the order that the items are listed in the source.

 .box {
          display: flex;
          flex-direction: row;
        }
        .box :nth-child(1) { order: 2; }
        .box :nth-child(2) { order: 3; }
        .box :nth-child(3) { order: 1; }
        .box :nth-child(4) { order: 3; }
        .box :nth-child(5) { order: 1; }
    
    

The order property is designed to lay the items out in ordinal groups. What this means is that items are assigned an integer that represents their group.

The items are then placed in the visual order according to that
integer, lowest values first.

If more than one item has the same integer value, then within that group the items are laid out as per source order.

As an example, I have 5 flex items, and assign order values as follows:

Source item 1: order: 2
Source item 2: order: 3
Source item 3: order: 1
Source item 4: order: 3
Source item 5: order: 1

These items would be displayed on the page in the following order:

Source item 3: order: 1
Source item 5: order: 1
Source item 1: order: 2
Source item 2: order: 3
Source item 4: order: 3

Items have a number showing their source order which has been rearranged.

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/116349.html

相关文章

  • Flex 项目属性:flex 布局示例

    flex属性: flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选。 该属性有两个快捷值:auto (1 1 auto) 和 none (0 0 auto)。 下面来看看使用项目属性flex的两个示例: 一、 CSS: 1 2 body{ margin: 0;padding: 0;font-siz...

    levinit 评论0 收藏0
  • 搭建移动端布局框架:整合flex

    摘要:概述在移端的兼容并不是很好但是在移动端的支持却是很好而且布局对移动端布局来说简直就是福音但是没有经过整和处理用布局也算是艰难所以打算搭建一套基于的移动端布局工具来学习容器类容器工具类这是对和属性的封装将一个元素变成横向的容器将一个元素变成 0x001 概述 flex在移pc端的兼容并不是很好,但是在移动端的支持却是很好,而且flex布局对移动端布局来说简直就是福音.但是没有经过整和...

    icyfire 评论0 收藏0
  • flex布局demo

    摘要:普通投诉处理中心审批承认立即处理。 示例一: * { margin: 0; padding: 0; } html { height: 100%; } body { height...

    BingqiChen 评论0 收藏0
  • 初探flex布局

    摘要:一布局概述布局是一种较新盒子模型,在布局模型中,弹性容器的子元素的排布可以比较灵活,可以根据容器的大小自动扩展或收缩其大小。下面我们来看用布局怎么解决这些问题。所以学会使用布局是非常有必要的。想详细了解布局请点击这里。 一 flex布局 1.1 flex概述 flex布局是一种较新CSS盒子模型,在flex布局模型中,弹性容器的子元素的排布可以比较灵活,可以根据容器的大小自动扩展或收缩...

    Jeffrrey 评论0 收藏0
  • flex-grow、flex-shrink、flex-basis和九宫格布局理解

    摘要:一属性定义剩余空间的分成。的默认值为,的值为时不缩放。示例代码代码当父元素的宽度大于三个子元素的宽度时,三个子元素的宽度会放大。使用实现代码代码参考文章布局下的属性详解布局九宫格布局的方法汇总更新中 一、flex-grow、flex-shrink、flex-basis属性 flex-grow: 定义剩余空间的分成。默认为0,即如果存在剩余空间,也不放大。flex-shrink: 定义...

    孙吉亮 评论0 收藏0

发表评论

0条评论

Forest10

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<