列表

详情


CSS21. 双列布局 - 浮动

描述

 自适应的双列布局利用浮动、外边和触发父级BFC即可实现,这种方法主要是因为BFC的高度计算会包含其内的浮动元素的高度,父盒子会被撑开。
 现在给类名为"container"的父盒子添加"overflow: hidden"属性,使该父盒子成为BFC。继续给类名为"left"的盒子设置"float: left"和"width: 100px"属性,使该盒子成为浮动元素并且需要一个固定的宽度。最后再给类名为"right"的盒子设置左外边距"margin-left: 100px"属性,该属性值需要和左浮动的盒子宽度一致。此时父盒子的高度会根据左边浮动元素、右边内容区中高度较高的一方进行计算,并且右边内容区的宽度自适应,最好是根据需要,配合最大或最小宽度进行设置。
 完成以上所讲的步骤即可通过测试,进入下一节的学习吧。

原站题解

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

{"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            .container {\n                border: 1px solid black;\n                overflow:hidden;\n            }\n            .left {\n                border: 1px solid black;\n                float:left;\n                width:100px;\n            }\n            .right{\n                margin-left: 100px\n            }\n        </style>\n    </head>\n    <body>\n    \t<section class=\"container\">\n            <article class=\"left\"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>\n            <article class=\"right\"></article>\n        </section>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1745ms, 内存消耗: 77824KB, 提交时间: 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            .container {\n                border: 1px solid black;\n                overflow: hidden;\n            }\n            .left {\n                border: 1px solid black;\n                float: left;\n                width: 100px;\n            }\n            .right{\n                \n                margin-left:100px;\n                \n            }\n        </style>\n    </head>\n    <body>\n    \t<section class=\"container\">\n            <article class=\"left\"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>\n            <article class=\"right\"></article>\n        </section>\n    </body>\n</html>","libs":[]}

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

{"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            .container {\n                border: 1px solid black;\n                overflow:hidden;\n            }\n            .left {\n                border: 1px solid black;\n                float:left;\n                width:100px;\n            }\n            .right {\n                margin-left:100px;\n                \n            }\n        </style>\n    </head>\n    <body>\n    \t<section class=\"container\">\n            <article class=\"left\"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>\n            <article class=\"right\"></article>\n        </section>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1746ms, 内存消耗: 77876KB, 提交时间: 2022-01-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            .container {\n                border: 1px solid black;\n                overflow:hidden;\n            }\n            .left {\n                border: 1px solid black;\n                float:left;\n                width:100px;\n            }\n            .right{\n                margin-left:100px;\n                background-color:red;\n            }\n        </style>\n    </head>\n    <body>\n    \t<section class=\"container\">\n            <article class=\"left\"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>\n            <article class=\"right\"></article>\n        </section>\n    </body>\n</html>","libs":[]}

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

{"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            .container {\n                border: 1px solid black;\n                overflow: hidden;\n            }\n            .left {\n                border: 1px solid black;\n                float: left;\n                width: 100px;\n            }\n            .right{\n                margin-left: 100px\n            }\n        </style>;\n    </head>\n    <body>\n    \t<section class=\"container\">\n            <article class=\"left\"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>\n            <article class=\"right\"></article>\n        </section>\n    </body>\n</html>","libs":[]}

上一题