栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

CSS实现页面九宫格布局的简单示范

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一、效果图:
2016627113915155.jpg (175×173)

三、布局二(各浏览器兼容性良好)

CSS Code复制内容到剪贴板
  1.   
  2.   
  3.   
  4.   
  5. 九宫格布局   
  6.   
  7.   
  8.   
  9.   
  10.   
  11.   
  12. body{margin:0;padding:0;}   
  13. .grid_wrapper{   
  14.  width: 170px;   
  15.  height: 170px;   
  16.  margin-left: auto;   
  17.  margin-right: auto;   
  18. }   
  19. .grid{   
  20.  margin-left: 5px;   
  21.  margin-top: 5px;   
  22. }   
  23. .grid:after{   
  24.  content: ".";   
  25.  display: block;   
  26.  line-height: 0;   
  27.  height: 0;   
  28.  clear: both;   
  29.  visibility: hidden;   
  30.  overflow: hidden;   
  31. }   
  32. .grid a,.grid a:visited{   
  33.  float: left;   
  34.  display: inline;   
  35.  border: 5px solid #ccc;   
  36.  width: 50px;   
  37.  height: 50px;   
  38.  text-align: center;   
  39.  line-height: 50px;   
  40.  margin-left: -5px;   
  41.  margin-top: -5px;   
  42.  position: relative;   
  43.  z-index: 1;   
  44. }   
  45. .grid a:hover{   
  46.  border-color: #f00;   
  47.  z-index: 2;   
  48. }   
  49.   
  50.   
  51.   
  52. "grid_wrapper">   
  53.  "grid">   
  54.   "#" title="1">1   
  55.   "#" title="2">2   
  56.   "#" title="3">3   
  57.   "#" title="4">4   
  58.   "#" title="5">5   
  59.   "#" title="6">6   
  60.   "#" title="7">7   
  61.   "#" title="8">8   
  62.   "#" title="9">9   
  63.     
  64.   
  65.   
  66.   
  67.   

IE6下兼容有问题,效果图如下:
2016627114120994.jpg (175×228)

三、布局二(各浏览器兼容性良好)

CSS Code复制内容到剪贴板
  1.   
  2.   
  3.   
  4.   
  5. 九宫格布局   
  6.   
  7.   
  8.   
  9.   
  10.   
  11.   
  12. body,ul,li{margin:0;padding:0;}   
  13. .grid_wrapper{   
  14.  width: 170px;   
  15.  height: 170px;   
  16.  margin-left: auto;   
  17.  margin-right: auto;   
  18. }   
  19. .grid{   
  20.  margin-left: 5px;   
  21.  margin-top: 5px;   
  22.  list-style-type:none;   
  23. }   
  24. .grid:after{   
  25.  content: ".";   
  26.  display: block;   
  27.  line-height: 0;   
  28.  width:0;   
  29.  height: 0;   
  30.  clear: both;   
  31.  visibility: hidden;   
  32.  overflow: hidden;   
  33. }   
  34. .grid li{float:left;line-height: 50px;}   
  35. .grid li a,.grid li a:visited{   
  36.  display:block;   
  37.  border: 5px solid #ccc;   
  38.  width: 50px;   
  39.  height: 50px;   
  40.  text-align: center;   
  41.  margin-left: -5px;   
  42.  margin-top: -5px;   
  43.  position: relative;   
  44.  z-index: 1;   
  45. }   
  46. .grid li a:hover{   
  47.  border-color: #f00;   
  48.  z-index: 2;   
  49. }   
  50.   
  51.   
  52.   
  53. "grid_wrapper">   
  54.     
  55.   
  56. "#" title="1">1
  57.   
  58.   
  59. "#" title="2">2
  60.   
  61.   
  62. "#" title="3">3
  63.   
  64.   
  65. "#" title="4">4
  66.   
  67.   
  68. "#" title="5">5
  69.   
  70.   
  71. "#" title="6">6
  72.   
  73.   
  74. "#" title="7">7
  75.   
  76.   
  77. "#" title="8">8
  78.   
  79.   
  80. "#" title="9">9
  81.   
  82.     
  83.   
  84.   
  85.   
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/217651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号