html練習(5),html練習

來源:互聯網
上載者:User

html練習(5),html練習

這個練習主要簡單的展示了據對定位和相對定位;

在此說下html的定位:

1.static定位

這個是預設的方式,對static而言,left和right是不生效的。

2.relative定位(相對定位)

元素框偏離自身流對應的位置(靠left和top定位),元素仍然保持為定位前的形狀,它原本所佔的空間仍保留,從這一角度看,好像該元素仍然在文檔流/標準流中一樣。

注意:relative的參照點是它原來的位置,進行移動

3.absolute定位(絕對位置)

相當於元素從原來的位置脫離,並讓出自己的空間,後面的元素就會佔有讓出的空間。

注意:absolute定位是相對於離自己最近的那個非標準流盒子而言的。

4.fixed定位

元素框的表現類似於將position設定為absolute,不過其包含塊是視窗本身。


代碼:

html檔案(test5.html):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>作者:一葉扁舟</title><!--
/*練習絕對位置和相對定位*/
    --><meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="./test5.css">

  </head>  
  <body>
    <h1>練習html的定位,包括絕對位置和相對定位</h1>
    <div class = "class1">
   相對定位
    <div class = "style1">這是第一個方格</div>
    <div class = "style1" id = "style2">這是第二個方格</div>
    <div class = "style1">這第三個方格</div>
   <div class = "style1">這是第四個方格</div>
   </div>
   <div class ="class1">
   絕對位置
    <div class = "style1">這是第五個方格</div>
    <div class = "style1" id = "style3">這是第六個方格</div>
    <div class = "style1">這第七個方格</div>
   <div class = "style1">這是第八個方格</div>
   </div>
  </body>
</html>


CSS檔案(test5.css):


.style1 {
width:100px;
height:70px;
background-color:red;
margin-top:12px;
margin-left:3px;
float:left;
}

body {
width:800px;
height:500px;
border:2px solid blue;
background-color:green;

}




#style2 {
/*使用相對定位*/
position:relative;
left:110px;
top:90px;
}


div.class1 {
width:700px;
height:200px;
border:1px solid gray;
}

#style3 {
/*使用絕對位置*/
position:absolute;
left:400px;
top:300px;
}


啟動並執行:



HTML5+CSS3網頁設計案例教程課後習題

1046: 找不到類型,或者它不是編譯時間常數: Ic
 
html5 測試頁面

HTML5測試頁面、IE9微軟測試網站總匯: www.win7en.com/strive/304.html目前最全的
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.