<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 27,comments - 2,trackbacks - 0
    HTML的定位
    HTML中要顯示有層次時用定位;定位有絕對定位,相對定位和固定定位。
    1.絕對定位:在選擇器中用position:absolute;此時它有類似與浮動的效果,相當于脫離了文檔流,如:
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" 
     3 <head>
     4     <title></title>
     5     <style type="text/css">
     6         body{
     7             margin:0px;;
     8         }
     9         .div1{
    10             width:100px;
    11             height:100px;
    12             background-color:#669900;
    13             position:absolute;
    14         }
    15         .div2{
    16             width:200px;
    17             height:50px;
    18             background-color:#aa00ff;
    19         }
    20     </style>    
    21 </head>
    22 <body>
    23     <div class="div1">div1</div>
    24     <div class="div2">div2</div>
    25 </body>
    26 </html>

    此時div1像浮動了,div2補上div1的位置(即有浮動的效果,div2被div1遮住了)
    此時如果定義它的高和距離左右,定義的是該塊距離它的上一級(即它的父)的距離
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" 
     3 <head>
     4     <title></title>
     5     <style type="text/css">
     6         body{
     7             margin:0px;;
     8         }
     9         .div1{
    10             width:100px;
    11             height:100px;
    12             background-color:#669900;
    13             position:absolute;
    14             top:10px;
    15             right:10px;
    16         }
    17         .div2{
    18             width:200px;
    19             height:50px;
    20             background-color:#aa00ff;
    21         }
    22     </style>    
    23 </head>
    24 <body>
    25     <div class="div1">div1</div>
    26     <div class="div2">div2</div>
    27 </body>
    28 </html>

    2.相對定位:position:relative;相對定位也有浮動的效果,只是它相對于原來的位置發生了偏移。例如: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" 
     3 <head>
     4     <title></title>
     5     <style type="text/css">
     6         body{
     7             margin:0px;;
     8         }
     9         .div1{
    10             width:100px;
    11             height:100px;
    12             background-color:#669900;
    13             position:relative;
    14             top:10px;
    15             left:10px;
    16         }
    17         .div2{
    18             width:200px;
    19             height:50px;
    20             background-color:#aa00ff;
    21         }
    22     </style>    
    23 </head>
    24 <body>
    25     <div class="div1">div1</div>
    26     <div class="div2">div2</div>
    27 </body>
    28 </html>

    當在body中為絕對定位時,其父為相對定位如: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4     <title></title>
     5     <style type="text/css">
     6         body{
     7             margin:0px;
     8         }
     9         div{
    10             width:200px;
    11             height:200px;
    12         }
    13         .div1 {
    14             background-color:#ccc;
    15             position:absolute;
    16             bottom:0px;
    17             right:0px;
    18             z-index:999;
    19         }
    20         .div2 {
    21             margin-left:60px;
    22             width:500px;
    23             height:300px;
    24             background-color:#ff6600;
    25             position:relative;
    26         }
    27         
    28     </style>
    29 </head>
    30 <body>    
    31     <div class="div2">DIV2
    32         <div class="div1">DIV1</div>
    33     </div>
    34 </body>
    35 </html>

    此時div1的位置是相對于div2的位置來說的。
    3.固定定位:固定定位個人認為可以理解為固定于瀏覽器邊框,不隨滾動條的滾動而滾動:如:
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" 
     3 <head>
     4     <title></title>
     5     <style type="text/css">
     6         body{
     7             margin:0px;;
     8         }
     9         .toolbar{
    10             height:30px;
    11             width:100%;
    12             background-color:green;
    13             position:fixed;
    14             top:0px;
    15             left:0px;
    16         }
    17         .div{
    18             width:150px;
    19             height:150px;
    20             background-color:#ff0000;
    21         }
    22     </style>    
    23 </head>
    24 <body>
    25     <div class="toolbar"></div><br/>
    26     <div class="div">div1</div><br/>
    27     <div class="div">div2</div><br/>
    28     <div class="div">div3</div><br/>
    29     <div class="div">div4</div><br/>
    30     <div class="div">div5</div><br/>
    31     <div class="div">div6</div><br/>
    32     <div class="div">div7</div><br/>
    33     <div class="div">div8</div>    <br/>
    34     <div class="div">div9</div><br/>
    35     <div class="div">div0</div><br/>
    36 </body>
    37 </html>
    posted on 2011-12-01 18:57 魏文甫 閱讀(5300) 評論(1)  編輯  收藏

    FeedBack:
    # HTML中的定位
    2014-09-11 21:27 | 令狐沖
    詞匯  回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 在线观看免费中文视频| 99免费在线视频| 成年人在线免费观看| 亚洲国产精品成人精品软件| 日韩中文字幕免费视频| 亚洲va久久久噜噜噜久久男同 | 亚洲视频免费在线观看| 精品无码无人网站免费视频| 亚洲色欲或者高潮影院| 1000部免费啪啪十八未年禁止观看| 亚洲精品在线免费观看视频| 国内精品乱码卡1卡2卡3免费| 亚洲中文字幕久在线| 好男人看视频免费2019中文| 亚洲AV色欲色欲WWW| 免费一级成人毛片| 一级毛片a免费播放王色| 亚洲精品国精品久久99热一| 日韩在线永久免费播放| 亚洲大香人伊一本线| 日韩一区二区在线免费观看| 免费国产污网站在线观看不要卡| 国产亚洲一区区二区在线| 成人无码WWW免费视频| 亚洲一区在线观看视频| 国产成人免费一区二区三区| aa级毛片毛片免费观看久| 99久久亚洲精品无码毛片| 在线精品免费视频| 免费一区二区三区在线视频| 亚洲成AV人片在线观看无| 免费H网站在线观看的| 狼色精品人妻在线视频免费| 国产精品亚洲аv无码播放| 在线观看免费高清视频| 人妻仑刮八A级毛片免费看| 亚洲AV永久无码精品| 成人无码区免费A片视频WWW | 男人的天堂av亚洲一区2区| 亚洲中文字幕在线观看| 一本岛高清v不卡免费一三区|