写在前面的话:

css3盒子布局,可以更简单直观的均分页面某一个div,并且还可以达到均分后的每一个元素中的内容上下居中、左右居中,但是该模型对浏览器的版本有要求:

{
display: -webkit-box; /* Firefox 30+,Chrome 4+, Safari 3.1, iOS Safari 3.2+ */
display: -moz-box; /* Firefox 17- */
display: -webkit-flex; /* Chrome 21+, Safari 6.1+, iOS Safari 7+, Opera 15/16 */
display: -moz-flex; /* Firefox 18+ */
display: -ms-flexbox; /* IE 10 */
display: flex; /* Chrome 29+, Firefox 22+, IE 11+, Opera 12.1/17/18, Android 4.4+ */
}
建议使用display: flex;因为display: -webkit-box;除了ie外都支持,但是在火狐和chrome上对该样式的解析又不一样,容易导致火狐和chrome样式混乱,并且火狐和chorme都出现盒子中的元素会改变盒子布局的长宽比,要不然就需要写两种样式display: -webkit-flex和display: -moz-flex;但这会导致写很多无意义的代码,所以也不建议使用,如果不针对低版本的ie开发,那么display: flex;无疑是更好的选择
效果1:
效果2:
代码:
 <style>
#Settings-div {
width: %;
height: 500px;/*开启盒子模型的框必须写长宽*/
background-color: #fff;
display: flex;/*开启盒子布局*/
flex-flow: column;/*竖向布局,指width不变height改变*/
/* display: -webkit-box;
-webkit-box-orient: vertical//竖向布局*/
} #Settings-header {
width: %;
height: .5em;/*如果不想按比例分配长宽可以自己写固定样式*/
line-height: .5em;
text-align: center;
font-size: .5em;
border-bottom: 1px solid #e5e5e5;
background-image: -moz-linear-gradient(top,#ffffff,#f7f7f7);
} #Content {
flex: ;
display: flex;
flex-flow: row;/*横向布局,如果是display: -webkit-box;则不用写布局方式,因为浏览器均默认为横向*/
} #Settings-list {
flex: ;
display: flex;
height: %;
flex-flow: column;
} #Settings-content {
flex: ;
height: %;
} #Settings-list div {
/*display: -webkit-box;//声明盒子模型下的所有div都按盒子模型布局
-webkit-box-align: center;//上下居中
-webkit-box-pack: center;//左右居中*/
display: flex;
justify-content: center;/*左右居中*/
align-items: center;/*上下居中*/
} .list-title {
flex: ;/*不单单是id可以写class也可以*/
background-image: -moz-linear-gradient(top,#ffffff,#f7f7f7);/*页面元素背景从上到下颜色渐变,怕你们看不懂,虽然与主题无关-moz是只能火狐识别的单独样式,-webkit是chrome、Safari、Opera为主的浏览器识别的样式 */
font-size: .2em;
border-right: 1px solid #e5e5e5;
} .list-content {
flex: ;
background-color: #f7f7f7;
border-top: 1px #e5e5e5 solid;
cursor: pointer;
border-right: 1px solid #e5e5e5;
} .action {
border-left: 5px solid #0094ff;
} .select {
background-color: #fff;
border-right: 0px;
} #Content-one {
width: %;
height: %;
} #Content-two {
width: %;
height: %;
} #Content-twodiv {
width: %;
height: %;
display: flex;
flex-flow: column;
}
     /*由于没有给#Content-twodiv底下的div写布局模式,所以底下的div中的元素没用居中*/
#Content-two1 {
flex: ;
width: %;
display: flex;
flex-flow: row;
} #Content-two2 {
flex: ;
} #Content-three {
display: none;
} #form1 {
width: %;
height: %;
display: -webkit-box;/*另一种要写很多无意义的代码的写法*/
display: -moz-box;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
}
     /*完全无意的浪费时间写的样式,实在是不推荐*/ 
#form1 div {
display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;
display: -moz-box;
-moz-box-align: center;
-moz-box-pack: center;
} #form1-header {
width: %;
height: 50px;
font-size: .3em;
border-bottom: 1px solid #e5e5e5;
} #table {
width: %;
table-layout: auto;
margin-top: 10px;
} #table td {
width: %;
height: 40px;
line-height: 40px;
} .table-left {
text-align: right;
padding-right: 20px;
} .table-right {
padding-left: 20px;
} #save1 {
background-color: #aa56ff;
color: #ffffff;
width: 80px;
height: 35px;
border: 0px;
box-shadow: 2px 4px 6px #;
cursor: pointer;
} #save2 {
background-color: #aa56ff;
color: #ffffff;
width: 80px;
height: 35px;
border: 0px;
box-shadow: 2px 4px 6px #;
cursor: pointer;
} #age {
width: 25px;
border-color: #d8d8d8 #e5e5e5 #e5e5e5 #d8d8d8;
border-style: solid;
border-width: 1px;
} .table-right select {
width: 100px;
height: 30px;
border-color: #d8d8d8 #e5e5e5 #e5e5e5 #d8d8d8;
border-style: solid;
border-width: 1px;
}
</style>
<div id="Settings-div">
<div id="Settings-header">
<span>个人设置</span>
</div>
<div id="Content">
<div id="Settings-list">
<div class="list-title action">
<img src="~/images/user.png" />
<span>个人资料</span>
</div>
<div class="list-content select" data-leve="">
<span>基本资料</span>
</div>
<div class="list-content" data-leve="" style="border-bottom:1px #e5e5e5 solid ;">
<span>头像设置</span>
</div>
<div class="list-title">
<img src="~/images/mi.png" />
<span>隐私设置</span>
</div>
<div class="list-content" style="border-top:1px #e5e5e5 solid ;" data-leve="">
<span>修改密码</span>
</div>
</div>
<div id="Settings-content">
<div id="Content-one" class="content">
<form id="form1">
<div id="form1-header">
<span>基本资料</span>
</div>
<table id="table">
<tr>
<td class="table-left">性别:</td>
<td class="table-right">
<input type="radio" name="sex" value="男" checked />男
<input type="radio" name="sex" value="女" />女
</td>
</tr>
<tr>
<td class="table-left">年龄:</td>
<td class="table-right"><input type="text" name="age" id="age" value="" />岁</td>
</tr>
<tr>
<td class="table-left">居住地:</td>
<td class="table-right">
<select>
<option value="">请选择</option>
</select>
<select>
<option value="">请选择</option>
</select>
</td>
</tr>
</table>
<div>
<input type="button" id="save1" value="保存" />
</div>
</form>
</div>
<div id="Content-two" class="content" style="display:none;">
<div id="Content-twodiv">
<div id="Content-two1">
<div style="flex:2;background-color:#e2e2e2;"> </div>
<div style="width:290px;"></div>
</div>
<div id="Content-two2">
<form id="upload-imgs" action="/FileUpload/FileImages" method="post" enctype="multipart/form-data">
<input type="button" value="上传图片" style="" />
<input type="file" name="img" value="" style="opacity:0; margin-left:-80px;width:80px;cursor:pointer;" onchange="uploadFile(this)" />
</form>
</div>
</div>
</div>
<div id="Content-three" class="content" style="display:none;"> </div>
</div>
</div> </div>

css3的盒子模型布局的更多相关文章

  1. CSS3弹性盒模型布局模块介绍

    来源:Robert’s talk原文:http://robertnyman.com/2010/12/02/css3-flexible-box-layout-module-aka-flex-box-in ...

  2. css3弹性盒子模型之box-flex

    css3弹性盒子模型之box-flex 浏览器支持 目前没有浏览器支持 box-flex 属性. Firefox 支持替代的 -moz-box-flex 属性. Safari.Opera 以及 Chr ...

  3. css3弹性盒子模型

    当下各种手机,平板尺寸不一,如果盒模型只能固定尺寸,不能随意压缩,将不能很好的迎合这个时代.所以css3推出了新的盒模型——弹性盒子模型(Flexible Box Model). 弹性盒模型可以水平布 ...

  4. 浅谈 css3 box盒子模型以及box-flex的使用

    display:box;box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典的一个布局应用就是布局的垂直等高.水平均分.按比例划分.   一.使 ...

  5. css3弹性盒子 flex布局

    CSS3 弹性盒 1.display:flex 说明: 设置为弹性盒(父元素添加) 2.flex-direction(主轴排列方式) 说明: 顺序指定了弹性子元素在父容器中的位置 row 默认在一行内 ...

  6. CSS3之盒子模型

    display:box 使子元素成行排列如果父级宽度小于子级盒子 不会把超出部分挤出下面 而是直接超出 -box-orient:vertical 使盒子垂直显示  默认水平显示 -box-direct ...

  7. CSS3 Box-sizing(盒子模型)

    http://www.w3cplus.com/content/css3-box-sizing http://tantek.com/CSS/Examples/boxmodelhack.html box- ...

  8. css3弹性盒子模型——回顾。

    1.box-flex属性规定框的子元素是否可伸缩其尺寸. 父元素必须要声明display:box;子元素才可以用box-flex. 语法:box-flex:value; 示例: <style&g ...

  9. display Flex 盒子模型布局兼容Android UC

    <!DOCTYPE html><html><head><meta charset="utf-8"><meta content= ...

随机推荐

  1. oc语言--protocol(协议)

    一.protocol 1.基本用途 1> 可以用来声明很多方法,但是不能用来声明成员变量 2> 只要某个类遵守了这个协议,就相当于拥有这个协议中的所有方法声明 3> 只要父类遵守了某 ...

  2. information_schema.referential_constraints 学习

    information_schema.referential_constraints 表用于查看外键约束 1.information_schema.referential_constraints表的常 ...

  3. path类和directory类对文件的路径或目录进行操作

    Path: 对文件或目录的路径进行操作(很方便)[只是对字符串的操作] 1.目录和文件操作的命名控件System.IO    2.string Path.ChangeExtension(string ...

  4. Log4net 可直接使用的配置

    config配置 <xml version="1.0"> <configuration> <configSections> <!--配置一 ...

  5. 互斥体与互锁 <第五篇>

    互斥体实现了“互相排斥”(mutual exclusion)同步的简单形式(所以名为互斥体(mutex)).互斥体禁止多个线程同时进入受保护的代码“临界区”.因此,在任意时刻,只有一个线程被允许进入这 ...

  6. Grunt制作个人博客简集

    原文:http://www.gbtags.com/gb/share/4916.htm GitHub地址:http://yansm.github.io/fromone/

  7. House Robber II 解答

    Question After robbing those houses on that street, the thief has found himself a new place for his ...

  8. 51操作各种demo 驱动

    24C02 bit write=0; //写24C02的标志: sbit sda=P2^0; sbit scl=P2^1; void delay0() { ;; } void start() //开始 ...

  9. struts.xml配置文件标签详解

    1.package: 作用:分模块化开发. 属性: name:包名. extends:由于struts2框架的一些核心功能的配置都在struts-default包中,所以一般都都直接或间接地继承str ...

  10. 解决红米等手机(移动端)无法触发touchend事件

    触屏事件的简单描述: js的触屏事件,主要有三个事件:touchstart,touchmove,touchend. 这三个事件最重要的属性是 pageX和 pageY,表示X坐标,Y坐标.touchs ...