进击的css!
来源:互联网 发布:云计算的安全问题 编辑:程序博客网 时间:2024/06/12 01:51
今天用easy-ui写了个登陆框,然后想要居中。于是在外围加了一个id=“mainBody”的div,然后css设为
#mainBody{width:30%;margin-top: 10%;margin-left: auto;margin-right: auto;}
之后,但是效果却是
margin-top设为10%,但是mainBody的外边距却将mainBody几乎挤到了中间。网上查了一下资料。
看到W3上这么说
<span style="font-family:SimSun;font-size:18px;">'margin-top', 'margin-bottom'Value: <margin-width> | inheritInitial: 0Applies to: all elements except elements with table display types other than table-caption, table and inline-tableInherited: noPercentages: refer to width of containing blockMedia: visualComputed value: the percentage as specified or the absolute lengthThese properties have no effect on non-replaced inline elements.</span>
于是,朕又,,,啊不是,是我又写了一个demo。
css代码
#father{width:90px;height:100px;background-color:#CCC;}#son{width:10px;height:10px;background-color:#000;margin-top:10%;margin-left:10%;}</span>
<div id="father"><div id="son"> </div> </div></span>
but!又出现了这个情况
margin-top呢!让你吃了吗!【css再次对您造成一次暴击!】
百度之,找到了原因:
贴吧上一个网友说:
根据W3C盒子模型的规范,一个盒子如果没有上补白(padding-top)和上边框(border-top),那么这个盒子的上边距会和其内部文档流中的第一个子元素的上边距重叠。
于是我又在#father里面加入了border:#000 1px solid;
然后,变成这样
好,继续。
查看一下盒模型
margin-top和margin-left的值为9,可见基数取自父元素的宽度
0 0
- 进击的css!
- 进击的2014
- 进击的程序员
- 进击的C++
- 进击的绿色
- 进击的对象池
- 进击的IOSer
- RxJava 进击的Rx
- GitHub的进击
- JVM的进击
- 正则表达式的进击
- 进击的自己
- 进击的多线程 --- 线程同步
- 进击的多线程 --- 线程定时器
- 进击的多线程 --- 线程池
- 进击的界面(1)
- 进击的大神之路
- 进击的Android之manifests
- QString中数字的使用
- C++实验题——牧羊人和邻居
- 《BIG DATA:大数据时代》(维克托·迈尔—舍恩伯格)
- Javascript 时间处理函数
- 解决office套件打开卡顿白屏的问题
- 进击的css!
- OnActionExecuting 中设置跳转指定网址或路由
- java server 多client异步socket通信demo
- 正则表达式的一些匹配规则
- poj 2456
- 庆安身份证号码户籍地址信息查询
- LeetCode的medium题集合(C++实现)十五
- Android Studio如何发布APK
- epoll详解-epoll学习笔记