web标准布局实例教程,用定位轻松解决CSS复杂布局 我相信来经典论坛学习标准的朋友,99%都不是为了进W3C,不是为了成为专业的研究人员,那么大家来的目的是什么呢?很简单,其实都是想通过标准的学习让自己多增加一项技能而已,让自己在找工作的时候不会在被“需要熟练掌握web标准”而难倒,在下面的实例中xhtml并没有什么语意,文章的目的只是让然大家能更好的掌握CSS中相对、绝对定位的用法(新手问此问题的确实很多),及如何有效的结合背景,实现比较复杂的布局。不足之处还望前辈们能指点一二,感谢!--------------------------------------------------第一步-------------------------------------------先来随便设计一个布局复杂点的(布局不规整)demo:document.body.clientWidth-300) {this.height=(document.body.clientWidth-300)*this.height/this.width;this.width=document.body.clientWidth-300}" border=0>--------------------------------------------------第二步-------------------------------------------我们来进行代码的编写model

-----------------------------------------------实际页面效果:--------------------------------------- model html,body{ margin:0; padding:0; background:#A1A9B6 url(http://www.okrmt.com/demo7.8/images/allbg.jpg); text-align:center; } #main{ margin:0 auto; position:relative; width:780px; height:659px; background:url(http://www.okrmt.com/demo7.8/images/model.jpg) no-repeat; } #main #menu{ position:absolute; right:12px; width:354px; height:115px; background:url(http://www.okrmt.com/demo7.8/images/menu.gif) no-repeat; } #main #menu a,#main #menu a#page{ float:left; width:112px; height:30px; } #main #menu a#about{ width:80px; height:55px; } #main #menu a#services{ width:70px; height:80px; } #main #menu a#contacts{ width:80px; height:115px; } #main #menu a:hover{ background: url(http://www.okrmt.com/demo7.8/images/menu.gif) no-repeat; } #main #menu a#page:hover{ background-position: 0px -115px; } #main #menu a#about:hover{ background-position: -112px -115px; } #main #menu a#services:hover{ background-position: -192px -115px; } #main #menu a#contacts:hover{ background-position: -262px -115px; } #main h1{ position:absolute; top:0;left:1px; width:151px; height:56px; background:url(http://www.okrmt.com/demo7.8/images/logo.jpg) no-repeat; } #main h2{ position:absolute; top:133px; right:7px; width:404px; height:190px; background:url(http://www.okrmt.com/demo7.8/images/about.gif) no-repeat; } #main h6{ position:absolute; bottom:75px; right:10px; width:265px; height:44px; background:url(http://www.okrmt.com/demo7.8/images/cars-logo.gif) no-repeat; } [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]好了,这次的实例教程就结束了,希望对大家以后进行xhtml网页的设计,布局能有所帮助!再见.