display_inline-block_table-cell

1、display:inline-block;

兼容性:兼容到IE7+,Chrome,Firefox

html:

 <ul class="list">
<li>首页</li>
<li>文章列表</li>
<li>关于我</li>
</ul>
<ul class="list">
<a href="#">首页</a>
<a href="#">文章列表</a>
<a href="#">关于我</a>
</ul>

css:

 /*reset-style*/
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:;padding:;}
ul,ol{list-style:none;}
body{font-size:12px;font-family:"Microsoft yahei";}
a{text-decoration:none;}
/*基本页面样式*/
.list{
width:350px; margin:50px auto;
}
.list li{
display:inline-block;width:100px;height:30px;line-height:30px;text-align:center;border:1px solid #666;
}
.list a{
display:inline-block;width:100px;height:30px;line-height:30px;text-align:center;border:1px solid #666;
}
/*解决在IE6/7下,ul的子元素li不能在同一行显示的问题*/
.list li{*display:inline;*zoom:;} /*下面的样式是为了去掉display:inline-block之间的空隙。*/
/*1--在父级元素上添加font-size为0,为了不影响子元素的font-size,我们也要在子元素.list li 和 .list a添加{font-size:12px}来覆盖父级元素的font-size*/
.list{font-size:;}.list li{font-size:12px;}.list a{font-size:12px;} /*2--Safari5不支持font-size:0,解决方法:在父级元素上使用 letter-spacing:-5px,为了不影响子元素需要在子元素重新设置值回默认值*/
@media screen and (-webkit-min-device-pixel-ratio:0){
.list{letter-spacing:-5px;}
}
.list li{letter-spacing:normal;}.list a{letter-spacing:normal;} /*3--使用*word-spacing:-1px; 解决IE6,7下产生的1px间隙bug,如下在父级元素多添加如下代码.list{ *word-spacing:-1px; }。同样为了使子元素不受影响需要添加word-spacing的默认值。*/
.list{*word-spacing:-1px;}
.list li{ *word-spacing:normal;} .list a { *word-spacing:normal;}

2、display:table-cell;

display:table-cell 目前IE8+浏览器都支持,IE6,7不支持,我们都知道单元格有一些特别的属性,比如图片垂直居中,文字垂直居中等。但是display:table-cell不能与float:left或者position:absolute属性等同用。对margin值无反应,支持padding属性。

demo1 - display-table-cell-图片居中显示:

兼容性:兼容到IE8+,Chrome,Firefox

html:

 <div class="box">
<ul>
<li><img src="bg.png"></li>
<li><img src="bg.png"></li>
</ul>
</div>

css:

 /*reset-style*/
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:;padding:;}
ul,ol{list-style:none;}
body{font-size:12px;font-family:"Microsoft yahei";}
a{text-decoration:none;} /*基本页面样式*/
.box{width:500px;height:300px;margin:30px auto;border:1px solid #ccc;}
ul{width:100%;height:100%;}
ul li{width:250px;height:300px;;display:table-cell;text-align:center;vertical-align:middle;}
ul li:first-child{border-right:1px solid #ccc;}

demo2 - display-table-cell-两栏自适应布局:

兼容性:兼容到IE7+,Chrome,Firefox

html:

 <div class="box">
<ul class="list">
<li><a href="#">首页</a></li>
<li><a href="#">文章列表</a></li>
<li><a href="#">评论列表</a></li>
<li class="about"><a href="#">关于我</a></li>
</ul>
<div class="content">
<p class="head">标题:上海欢迎你!</p>
<p>简介:上海是一座国家历史文化名城,拥有深厚的近代城市文化底蕴和众多历史古迹。江南传统吴越文化与西方传入的工业文化相融合形成上海特有的海派文化,上海人多属*系使用吴语。早在宋代就有了“上海”之名,1843年后上海成为对外开放的商埠并迅速发展成为远东第一大城市,今日的上海已经成功举办了2010年世界博览会、中国上海国际艺术节、上海国际电影节等大型国际活动。</p>
</div>
</div>

css:

 /*reset-style*/
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:;padding:;}
ul,ol{list-style:none;}
body{font-size:12px;font-family:"Microsoft yahei";}
a{text-decoration:none;} /*基本页面样式*/
.box{width:100%;margin:30px auto;padding:20px;border:1px solid #ccc;overflow:hidden;box-sizing:border-box;*behavior:url(boxsizing.htc);}
/* *behavior:url(boxsizing.htc);解决IE7不支持box-sizing:border-box;的问题 */
.list{width:200px;background:#eee;float:left;}
.list li{height:35px;line-height:35px;display:block;border-bottom:1px solid #ccc;}
.list .about{border:;}
.list li a{display:block;text-align:left;font-size:16px;padding-left:35px;color:#333;}
.content{display:table-cell;*display:inline-block;font-size:14px;padding-left:20px;}
.content .head{line-height:30px;font-weight:bold;}
.content p{line-height:22px;}
上一篇:Java基础学习总结(40)——Java程序员最常用的8个Java日志框架


下一篇:javaweb项目中的classpath