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

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - 魔豆

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>

效果如下: