列表

详情


CSS17. display - flex - order

描述

 使用Flexbox的order属性,可以完全摆脱项目在源码中顺序的约束。默认情况下,每个项目的order值都为0,意味着按照他们在源代码中的顺序进行排列。可以观看右边的代码效果,从设计上说,把图片放在最前面可以抓住读者的眼球,是比较好的设计方式,但是对于浏览器而言,拿到标题并且直接将标题呈现给读者的代价一定比获取一张照片并渲染出来小得多。所以可以考虑折中的方式,先渲染标题但是优先显示图片。
 现在给"img"图片标签设置"order: -1"属性,此时观察效果会发现图片的排列在标题之上,其他内容的相对位置不会变,它们的order值仍然是0。order的值不一定要连续,并且正负都可以。
 完成以上所讲的步骤即可通过测试,进入下一节的学习吧。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1743ms, 内存消耗: 77828KB, 提交时间: 2021-12-30

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n        <style type=\"text/css\">\n            * {\n                margin: 0;\n                padding: 0;\n                box-sizing: border-box;\n            }\n            section {\n                display: flex;\n                flex-direction: column;\n                text-align: center;\n            }\n                img{\n                    order: -1\n                }\n        </style>\n    </head>\n    <body>\n    \t<section>\n            <h2>countdown</h2>\n            <img src=\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fuploads.xuexila.com%2Fallimg%2F1912%2F1135-191202143454.jpg&refer=http%3A%2F%2Fuploads.xuexila.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639984107&t=eca951193e736a17eb96278117bcfb1f\" width=\"100%\">\n            <article>The countdown to Christmas starts here.</article>\n            <p><a href=\"#\">more</a></p>\n        </section>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1752ms, 内存消耗: 77900KB, 提交时间: 2022-01-23

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n        <style type=\"text/css\">\n            * {\n                margin: 0;\n                padding: 0;\n                box-sizing: border-box;\n            }\n            section {\n                display: flex;\n                flex-direction: column;\n                text-align: center;\n            }\n            img{order: -1;}\n        </style>\n    </head>\n    <body>\n    \t<section>\n            <h2>countdown</h2>\n            <img src=\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fuploads.xuexila.com%2Fallimg%2F1912%2F1135-191202143454.jpg&refer=http%3A%2F%2Fuploads.xuexila.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639984107&t=eca951193e736a17eb96278117bcfb1f\" width=\"100%\">\n            <article>The countdown to Christmas starts here.</article>\n            <p><a href=\"#\">more</a></p>\n        </section>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1753ms, 内存消耗: 77772KB, 提交时间: 2021-12-22

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n        <style type=\"text/css\">\n            * {\n                margin: 0;\n                padding: 0;\n                box-sizing: border-box;\n            }\n            section {\n                display: flex;\n                flex-direction: column;\n                text-align: center;\n            }\n            img{\n                order:-1;\n            }\n        </style>\n    </head>\n    <body>\n    \t<section>\n            <h2>countdown</h2>\n            <img src=\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fuploads.xuexila.com%2Fallimg%2F1912%2F1135-191202143454.jpg&refer=http%3A%2F%2Fuploads.xuexila.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639984107&t=eca951193e736a17eb96278117bcfb1f\" width=\"100%\">\n            <article>The countdown to Christmas starts here.</article>\n            <p><a href=\"#\">more</a></p>\n        </section>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1757ms, 内存消耗: 77776KB, 提交时间: 2022-02-03

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n        <style type=\"text/css\">\n            * {\n                margin: 0;\n                padding: 0;\n                box-sizing: border-box;\n            }\n            section {\n                display: flex;\n                flex-direction: column;\n                text-align: center;\n            }\n            img{\n                order:-1;\n            }\n         \n        </style>\n    </head>\n    <body>\n    \t<section>\n            <h2>countdown</h2>\n            <img src=\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fuploads.xuexila.com%2Fallimg%2F1912%2F1135-191202143454.jpg&refer=http%3A%2F%2Fuploads.xuexila.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639984107&t=eca951193e736a17eb96278117bcfb1f\" width=\"100%\">\n            <article>The countdown to Christmas starts here.</article>\n            <p><a href=\"#\">more</a></p>\n        </section>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1758ms, 内存消耗: 77772KB, 提交时间: 2021-12-21

{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n        <style type=\"text/css\">\n            * {\n                margin: 0;\n                padding: 0;\n                box-sizing: border-box;\n            }\n            section {\n                display: flex;\n                flex-direction: column;\n                text-align: center;\n            }\n            img{\n                order: -1;\n            }\n        </style>\n    </head>\n    <body>\n    \t<section>\n            <h2>countdown</h2>\n            <img src=\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fuploads.xuexila.com%2Fallimg%2F1912%2F1135-191202143454.jpg&refer=http%3A%2F%2Fuploads.xuexila.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639984107&t=eca951193e736a17eb96278117bcfb1f\" width=\"100%\">\n            <article>The countdown to Christmas starts here.</article>\n            <p><a href=\"#\">more</a></p>\n        </section>\n    </body>\n</html>","libs":[]}

上一题