|
--------------------------------------------------第一步-------------------------------------------
先來隨便設(shè)計一個布局復雜點的(布局不規(guī)整)demo:

--------------------------------------------------第二步-------------------------------------------
我們來進行代碼的編寫
<HTML>
<HEAD>
<TITLE>model</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<style>
html,body{
margin:0;
padding:0;
background:#A1A9B6 url(images/allbg.jpg);
text-align:center;
}
#main{
margin:0 auto;
position:relative; -------------------------------->我是相對定位
width:780px;
height:659px;
background:url(images/model.jpg) no-repeat;
}
#main #menu{
position:absolute;
right:12px;
width:354px;
height:115px;
background:url(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(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;-------->我是絕對定位,我相對與我的上一級#main來進行定位,因為他設(shè)置了position:relative;如果在我的父一級中沒有找到position:relative;那我就相對與body來定位了...
top:0;left:1px;
width:151px;
height:56px;
background:url(images/logo.jpg) no-repeat;
}
#main h2{
position:absolute;------------------>我也是絕對定位 我和上面提到的用法一樣
top:133px;
right:7px;
width:404px;
height:190px;
background:url(images/about.gif) no-repeat;
}
#main h6{
position:absolute;------------------>我也是絕對定位 我和上面提到的用法一樣
bottom:75px;
right:10px;
width:265px;
height:44px;
background:url(images/cars-logo.gif) no-repeat;
}
</style>
</HEAD>
<BODY>
<div id="main">
<div id="menu">
------------------------------------------------------------------------------>這個菜單是怎么工作的呢?
一張圖是怎么能實現(xiàn)背景切換呢?
呵呵,其實也很簡單?大家知道背景圖象中有:圖像橫縱坐標位置設(shè)置,此例子也正是運用這個特性,將擁有不同ID的鏈接A的背景進行偏移,以達到背景切換的目的。
<a href="#" id="page" title="page"></a>
<a href="#" id="about" title="about"></a>
<a href="#" id="services" title="services"></a>
<a href="#" id="contacts" title="contacts"></a>
</div>
<h1></h1>
<h2></h2>
<h6></h6>
</div>
</BODY>
</HTML>
-----------------------------------------------實際頁面效果:---------------------------------------
[Ctrl+A 全選 注:如需引入外部Js需刷新才能執(zhí)行]
好了,這次的實例教程就結(jié)束了,希望對大家以后進行xhtml網(wǎng)頁的設(shè)計,布局能有所幫助!再見.
HTML/CSS技術(shù):web標準布局實例教程,用定位輕松解決CSS復雜布局,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。