九宫格布局在制作一些Web App时还是经常可以用到的,中国E盟技术频道的小编在这里我们以一个大概的结构示例来作CSS实现页面九宫格布局的简单演示,不过需要注意IE6下的兼容性问题。
一、效果图:
三、布局二(各浏览器兼容性良好)
CSS Code复制内容到剪贴板
- css">
- "utf-8">
- "X-UA-Compatible"content="IE=edge">
- > type=
- body{margin:0;padding:0;}
- .grid_wrapper{
- width:170px;
- height:170px;
- margin-left:auto;
- margin-right:auto;
- }
- .grid{
- margin-left:5px;
- margin-top:5px;
- }
- .grid:after{
- content:".";
- display:block;
- line-height:0;
- height:0;
- clear:both;
- visibility:hidden;
- overflow:hidden;
- }
- .grida,.grida:visited{
- float:left;
- display:inline;
- border:5pxsolid#ccc;
- width:50px;
- height:50px;
- text-align:center;
- line-height:50px;
- margin-left:-5px;
- margin-top:-5px;
- position:relative;
- z-index:1;
- }
- .grida:hover{
- border-color:#f00;
- z-index:2;
- }
- "grid_wrapper">class=
- "grid">class=
- "#"title="1">1 >
- "#"title="2">2 >
- "#"title="3">3 >
- "#"title="4">4 >
- "#"title="5">5 >
- "#"title="6">6 >
- "#"title="7">7 >
- "#"title="8">8 >
- "#"title="9">9 >
IE6下兼容有问题,效果图如下:
三、布局二(各浏览器兼容性良好)
CSS Code复制内容到剪贴板
- "utf-8">
- "X-UA-Compatible"content="IE=edge">
- > type=
- body,ul,li{margin:0;padding:0;}
- .grid_wrapper{
- width:170px;
- height:170px;
- margin-left:auto;
- margin-right:auto;
- }
- .grid{
- margin-left:5px;
- margin-top:5px;
- list-style-type:none;
- }
- .grid:after{
- content:".";
- display:block;
- line-height:0;
- width:0;
- height:0;
- clear:both;
- visibility:hidden;
- overflow:hidden;
- }
- .gridli{float:left;line-height:50px;}
- .gridlia,.gridlia:visited{
- display:block;
- border:5pxsolid#ccc;
- width:50px;
- height:50px;
- text-align:center;
- margin-left:-5px;
- margin-top:-5px;
- position:relative;
- z-index:1;
- }
- .gridlia:hover{
- border-color:#f00;
- z-index:2;
- }
- "grid_wrapper">class=
-
"grid">
- "#"title="1">1>
- "#"title="2">2>
- "#"title="3">3>
- "#"title="4">4>
- "#"title="5">5>
- "#"title="6">6>
- "#"title="7">7>
- "#"title="8">8>
- "#"title="9">9>
小编带来的这篇CSS实现页面九宫格布局的简单演示,是不是特别的实用呢,更多关于CSS的内容,可以多多关注下中国E盟技术频道,我们会不断的更新。