網頁的本質就是超級文本標記語言,通過結合使用其他的Web技術(如:腳本語言、公共網關接口、組件等),可以創造出功能強大的網頁。因而,超級文本標記語言是萬維網(Web)編程的基礎,也就是說萬維網是建立在超文本基礎之上的。超級文本標記語言之所以稱為超文本標記語言,是因為文本中包含了所謂“超級鏈接”點。 學習CSS+DIV的朋友,今天本站來教你們如何使用div水平垂直居中設置技巧,相信知道DIV的人對水平垂直居中并不陌生吧,但是對于那些剛學習的菜鳥來說,還是有很打幫助的!下面請看本站慢慢為大家進行詳細的解說。 一、DIV水平居中設置技巧 在設計代碼中使用margin-left:auto;margin-right:auto; 可以讓你的div居中對齊。 在使用CSS的時候,在style屬性中加入.style{margin-left:auto;margin-right:auto;},同時也可以使用縮寫形式為: .style{margin:0 auto;}。 解釋: 數字0,表示上下邊距是0。然后左右居中。也可以按照需要設置成不同的值。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>水平垂直居中div演示效果</title> <style type="text/css"> .align-center{ position:fixed;left:50%;top:50%;margin-left:width/2;margin-top:height/2; } </style> </head> <body> <div class="align-center"> 水平垂直居中div演示效果 </div> </body> </html> 或者不使用上面的代碼,給body使用一個body{text-align:center;}屬性值,讓其全部居中。 二、DIV垂直居中設置技巧 關于垂直居中可以使用在CSS中代碼為:position:fixed;left:50%;top:50%;margin-left:width/2;margin-top:height/2; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>水平垂直居中div演示效果</title> <style type="text/css"> .align-center{ position:fixed;left:50%;top:50%;margin-left:width/2;margin-top:height/2; } </style> </head> <body> <div class="align-center">水平垂直居中div演示效果</div> </body> </html> 網站建設是一個廣義的術語,涵蓋了許多不同的技能和學科中所使用的生產和維護的網站。 |
溫馨提示:喜歡本站的話,請收藏一下本站!