
首先将以下代码加到你的全局CSS文件中:
/*1.reset browser defaults then reset the browser Font size*/
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fIEldset,input,textarea,p,
blockquote,th,td {margin:0; padding:0; }
table { border-collapse:collapse; border-spacing:0; }
fIEldset,img { border:0; }
address,caption,cite,code,dfn,em,strong,var { Font-style:normal; Font-weight:normal; }
ol,ul { List-style:none; }
caption,th { text-align:left; }
h1,h6 { Font-size:100%; Font-weight:normal; }
q:before,q:after { content:“; }
abbr,acronym { border:0; }
HTML {Font-size: 62.5%;}
然后,我们把字体大小Font-size设为10px如:
HTML {Font-size: 62.5%;}
这样我们就比较容易的通过em单位来设置页面字体的大小了,e.g
p {Font-size: 1.2em;}/* the same as 12px*/
h1 {Font-size: 2em;}/* the same as 20px */
2.水平居中(仅限固定宽度)
这个我想大家都会知道的,如:
div#container {margin: 0 auto;}
3.充分利用position中的absolute和relatively
4.居中,还是居中(纵横通杀)
div.popup { height:400px; wIDth:500px; position: absolute; top: 50%; left: 50%;}
div.popup { margin-top: -200px; margin-left: -250px;}
Memo:
&mIDdot;必须指定wIDth和height的固定值;
&mIDdot;position值为absolute;
&mIDdot;分别指定top与left为50%;
&mIDdot;设置margin-top和margin-left分别height和wIDth的负值的一半,也可以简写为:margin:-200px 0 0 -250px;
5.CSS也能复用
建立你的global CSS rules,充分在任何可以用到的页面用它吧,e.g
.left {float: left;}
.right {float: right;}
img .left { border:2px solID #aaaaaa; margin: 0 10px 0 0;}
img .right { border:2px solID #aaaaaa; margin: 0 0 0 10px; padding: 1px;}
6.ie6的margin BUG
当你设置div元素的float属性并指定了margin-left属性,在ie6或以下版本浏览的时候你可以会太跌眼镜,ie6怎么给你愉愉地加了margin的值呢?
解决方法:把div设为内联的就行了 e.g
div {float:left;margin:40px;display:inline;}
7.简单的导航菜单
xhtml:
<div ID="navbar">
<ul>
<li><a href=http://www.wfuyu.com>LIEHuo Design</a></li>
<li><a href=http://www.Google.com>Google</a></li>
<li><a href="http://bbs.lIEhuo.net/">LIEHuo BBS</a></li>
</ul>
</div>
CSS:
#navbar ul li {display:inline;margin:0 10px 0 0;}
#navbar ul li a {color: #333;display:block;float:left;padding:5px;}
#navbar ul li a:hover {background:#eee;color:black;} 总结
以上是内存溢出为你收集整理的Css+div 垂直居中对齐方式集锦全部内容,希望文章能够帮你解决Css+div 垂直居中对齐方式集锦所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)