惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 魔豆

oracle中使用unpivot实现列转行 推荐一个可以下载B站视频的工具 学习qt,做了一个小应用:随机点名提问系统 hadoop的eclipse插件 mysql5.5安装到最后一步卡死无响应的解决方法 Hbase各版本支持情况 Comparable接口的使用 css3实现动画效果 HTML5中使用EventSource实现服务器发送事件 HTML5中的Web Worker技术 使用visual studio code运行html 【转】解决chrome浏览器不支持audio和video标签的autoplay自动播放 spring mvc中添加对Thymeleaf的支持 Eclipse安装代码反编译插件Enhanced Class Decompiler 使用idea创建web项目 shell编程学习笔记(十二):Shell中的break/continue跳出循环 shell编程学习笔记(十一):Shell中的while/until循环 shell编程学习笔记(十):Shell中的for循环 shell编程学习笔记(九):Shell中的case条件判断
css3中的盒子模型
魔豆 · 2019-05-25 · via 博客园 - 魔豆

1、示例一

实现左右布局,左侧宽度200px,右侧自适配

代码如下:

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <style>
        .wrap {
            display: -webkit-box;
            display: -ms-flexbox;
            -webkit-box-orient: horizontal;
        }

        .child {
            border: 2px solid black;
            -webkit-box-align: center;
            margin: 10px;
            min-height: 200px;
            word-break: break-all;

        }

        .w200 {
            width: 200px;
        }

        .flex1 {
            -webkit-box-flex: 1;
            -ms-flex: 1;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div class="child w200">200px</div>
        <div class="child flex1">右侧内容2</div>
    </div>
</body>

</html>

说明:

display: -webkit-box;  适用于谷歌浏览器,火狐浏览器,IE Edge

display: -ms-flexbox;  适用于IE10、IE11,我试了IE8,IE9,都支持不了

效果如下:

2、示例二

实现左中右布局,左中右比例为:200px:1:2

代码如下:

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <style>
        .wrap {
            display: -webkit-box;
            display: -ms-flexbox;
            -webkit-box-orient: horizontal;
        }

        .child {
            border: 2px solid black;
            -webkit-box-align: center;
            margin: 10px;
            min-height: 200px;
            word-break: break-all;

        }

        .w200 {
            width: 200px;
        }

        .flex1 {
            -webkit-box-flex: 1;
            -ms-flex: 1;
        }

        .flex2 {
            -webkit-box-flex: 2;
            -ms-flex: 2;
        }        
    </style>
</head>

<body>
    <div class="wrap">
        <div class="child w200">200px</div>
        <div class="child flex1">中间内容</div>
        <div class="child flex2">右侧内容</div>
    </div>
</body>

</html>

效果如下:

3、示例三

在示例二的基础上,使用-webkit-box-direction修改布局顺序

代码如下(黄色背景为添加的代码):

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <style>
        .wrap {
            display: -webkit-box;
            display: -ms-flexbox;
            -webkit-box-orient: horizontal;
            -webkit-box-direction: reverse;
        }

        .child {
            border: 2px solid black;
            -webkit-box-align: center;
            margin: 10px;
            min-height: 200px;
            word-break: break-all;

        }

        .w200 {
            width: 200px;
        }

        .flex1 {
            -webkit-box-flex: 1;
            -ms-flex: 1;
        }

        .flex2 {
            -webkit-box-flex: 2;
            -ms-flex: 2;
        }        
    </style>
</head>

<body>
    <div class="wrap">
        <div class="child w200">200px</div>
        <div class="child flex1">中间内容</div>
        <div class="child flex2">右侧内容</div>
    </div>
</body>

</html>

通过指定-webkit-box-direction: reverse;显示顺序为从右到左显示。这个样式即使最新的IE11也是不支持的,在IE Edge浏览器上可以支持。

4、示例四

使用box-ordinal-group定义盒子布局的位置

代码如下:

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <style>
        .wrap {
            display: -webkit-box;
            display: -ms-flexbox; /* IE10+ */
            -webkit-box-orient:vertical;
        }

        .child {
            border: 1px solid black;
            margin: 10px;
            min-height: 200px;
            width: 200px;

        }

        .flex1 {
            -webkit-box-ordinal-group: 4;
            -ms-flex-order:4; /* IE10+ */
        }

        .flex2 {
            -webkit-box-ordinal-group: 3;
            -ms-flex-order:3; /* IE10+ */
        }

        .flex3 {
            -webkit-box-ordinal-group: 2;
            -ms-flex-order:2; /* IE10+ */
        }

        .flex4 {
            -webkit-box-ordinal-group: 1;
            -ms-flex-order:1; /* IE10+ */
        }        
    </style>
</head>

<body>
    <div class="wrap">
        <div class="child flex1"><img src="images/img1.png"></div>
        <div class="child flex2"><img src="images/img2.png"></div>
        <div class="child flex3"><img src="images/img3.png"></div>
        <div class="child flex4"><img src="images/img4.png"></div>
    </div>
</body>

</html>

效果如下:

 我本地的图片:

 示例五

本示例使用box-orient来指定盒子是横向排列还是竖向排列

使用box-pack来指定子容器在水平轴上的空间分配方式,是居左,居右,还是居中

使用box-align来指定子容器在竖轴上的空间分配方式,是居上,居下,还是居中

代码如下:

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
</head>
<style>
        .wrap {
            min-height: 600px;
            display: -webkit-box;
            display: -ms-flexbox;
            -webkit-box-orient:vertical; /* 子容器竖向排列 */
            -ms-flex-direction: column; /* 子容器竖向排列,IE10+ */
            flex-direction: column; /* 子容器竖向排列,IE10+ */
            -webkit-box-pack: center; /* 子容器在水平轴上的空间分配方式,可以是start、end或者center */
            -webkit-box-align: center; /* 子容器在竖轴上的空间分配方式,可以是start、end或者center */
            -ms-flex-align: center; /* 子容器在竖轴上的空间分配方式,可以是start、end或者center */
            -ms-flex-pack:center /* 子容器在水平轴上的空间分配方式,IE10+,可以是start、end或者center */
        }

        .flex {
            border: 1px solid black;
            margin: 10px;
            width: 200px;
        }
</style>
<body>
    <div class="wrap">
        <div class="flex"><img src="images/img1.png" ></div>
        <div class="flex"><img src="images/img2.png" ></div>
    </div>
</body>
</html>

效果如下: