【CSS】使用Bootstrap來編寫一個PC、平板、手機同時使用而且美觀的登陸頁面,cssbootstrap
Bootstrap如同前台架構,它已經布置好不少的CSS,前端開發的使用需要則直接調用即可。其網站的網址就是http://www.bootcss.com。使用Bootstrap能減少前端開發時候在CSS樣子的布置時間
需要使用Bootstrap先在官網(點擊開啟連結)下載組件即可,用於生產環境的Bootstrap版本(點擊開啟連結),Bootstrap3對2並不相容,建議直接根據其開發文檔使用Bootstrap3。
將Bootstrap解壓之後把得到的3個檔案夾css,fonts,js拷貝到網站目錄下面。如果是Eclipse的JSP Web Project的話就把它們放到WebRoot檔案夾下面。
之後就能夠在此網站目錄下的任何頁面調用Bootstrap為前端快速建模。
不過值得注意的是,不同瀏覽器對於Bootstrap解釋是不一樣的,其中IE對某些樣式讀不出來,但是基本的功能不受影響,頁面醜一點而已。
以下是IE與Google瀏覽器對同一頁面的對比:
一、基本目標
使用Bootstrap來編寫一個PC、平板、手機同時使用而且美觀的登陸頁面。
在PC上如果展開的話,各類元素會自動適應螢幕。
在手機上開啟這類的頁面的話,會直接適應手機螢幕,無需使用者自動調節。
二、基本思想
頁面的布局,根據Bootstrap固有的樣式設計如下:
三、製作過程
如下整個頁面具體代碼如下,下面將一個一個標籤來分析:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>登陸頁面</title><meta name="viewport"content="width=device-width,initial-scale=1.0,user-scalable=no"><link href="css/bootstrap.css" rel="stylesheet" media="screen"></head><body><div class="panel panel-info"><div class="panel-heading"><table frame="void"><tr><td><img src="images/img0.jpg" width="300px" height="300px" /></td><td>歡迎。請您先登入。</td></tr></table></div><div class="panel-body"><form class="form-horizontal" role="form" action="1.html"method="post"><div class="form-group"><label for="username" class="col-sm-2 control-label">使用者名稱:</label><div class="col-sm-10"><input type="text" name="username" class="form-control"placeholder="使用者名稱" id="username" /></div></div><div class="form-group"><label for="password" class="col-sm-2 control-label">密碼:</label><div class="col-sm-10"><input type="password" name="password" class="form-control"placeholder="密碼" id="password" /></div></div><div class="form-group"><div class="col-sm-offset-2 col-sm-10"><button type="submit" class="btn btn-info">登陸</button><small> 沒有帳號?<ahref="http://2.com">點擊註冊</a> </small></div></div></form></div></div></body></html>
1.<head>標籤
先在<head>標籤中,放入如下兩行代碼:
<head><title>登陸頁面</title><!--要求頁面自動適應瀏覽器的螢幕--><meta name="viewport"content="width=device-width,initial-scale=1.0,user-scalable=no"><!--聲明我要使用bootstrap--><link href="css/bootstrap.css" rel="stylesheet" media="screen"></head>
2.<body>標籤
(1)首先寫入<div class="panel panel-info"></div>,然後在其中放入代碼,其基本說明如:
(2)<div class="panel-heading">標籤
<div class="panel-heading"><!--設定表格對這個CSS圖層進行布局,在img標籤中加入align="left"是不好用的,圖象會向圖層外溢出--><!--同<table border="0">--><table frame="void"><tr><td><img src="images/img0.jpg" width="300px" height="300px" /></td><td>歡迎。請您先登入。</td></tr></table></div>
(3)<div class="panel-body">標籤下,先放入一個表單元素form class="form-horizontal" role="form" action="1.html" method="post">,此表單與HTML的普通表單相比,就是多了class屬性與role屬性,class屬性無需多說,如果值為form的話,表單即使有足夠位置,外標籤與輸入框也不會在同一行,如果值為現在的form-horizontal,那麼則效果所示。role屬性看不出有如何效果,此處僅僅是根據bootstrap的中文文檔添加的。
接下來,各個form表單下的元素如下:
<div class="panel-body"><form class="form-horizontal" role="form" action="1.html"method="post"><!--每一個屬性的外標籤與輸入框構成一個form-group元組--><div class="form-group"><!--如下的class屬性是為了其能夠根據螢幕的大小自動展開--><label for="username" class="col-sm-2 control-label">使用者名稱:</label><div class="col-sm-10"><!--此處的placholder意為不輸入任何東西的說明灰字,當然在IE8中無法解釋。id看不出有什麼作用,僅僅是根據Bootstrap中文文檔的要求而添加的--><input type="text" name="username" class="form-control"placeholder="使用者名稱" id="username" /></div></div><div class="form-group"><label for="password" class="col-sm-2 control-label">密碼:</label><div class="col-sm-10"><input type="password" name="password" class="form-control"placeholder="密碼" id="password" /></div></div><div class="form-group"><div class="col-sm-offset-2 col-sm-10"><!--此處的button與HTML的普通submit按鈕是有區別的,但不影響表單的提交--><button type="submit" class="btn btn-info">登陸</button><!--<small>標籤保證了這段文字與submit按鈕同一行--><small> 沒有帳號?<ahref="http://2.com">點擊註冊</a> </small></div></div></form></div>
至此,本頁面的開發完成。
html,css,朋友友們我現在用bootstrap做一個簡單的網頁,問導航條怎才可以在網頁當中兩邊留出點間隔?
bootstrap樣式採用的是層級樣式,就是從外向內一層層找,所以你在導覽列上直接寫css樣式是不行的,這優先順序沒有層級樣式高,你需要在bootstrap源檔案裡面的css裡面找到對應的樣式修改才行
bootstrap有一個配套的css檔案docscss,問在哪下載?
你可以到bootstrap的源碼倉庫(github)下載,曆史版本都有。 附一個目前的版本的地址:
github.com/twbs/bootstrap/
附3.0的,你可以另存新檔,或者用下載工具。
raw.github.com/...cs.css