課程
/前端開發(fā)
/Bootstrap
/玩轉(zhuǎn)Bootstrap(基礎(chǔ))
我覺得要是有這樣一個類會很方便啊,可惜text-center只能讓元素內(nèi)容左右居中顯示。
2016-04-15
源自:玩轉(zhuǎn)Bootstrap(基礎(chǔ)) 2-8
正在回答
<!DOCTYPE?html> <html> <head> ??<meta?charset="UTF-8"> ??<meta?http-equiv="X-UA-Compatible"?content="IE=edge"> ??<meta?name="viewport"?content="width=device-width,?initial-scale=1"> ??<title>絕對屏幕居中</title> ??<!--?Boostrap?--> ??<link?rel="stylesheet"?type="text/css"?href="css/bootstrap.min.css"> ??<link?rel="stylesheet"?type="text/css"?href=""> ??<!--?以下兩個插件是對IE8及以下版本瀏覽器支持html5元素和媒體查詢?--> ??<!--?[if?lt?IE?9]?--> ??<script?src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> ??<script?src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> ??<!--?[endif]?--> </head> <body> ??<div?id="d1"?style="position:?fixed;?width:?100px;?height:?100px;?background-color:?green;">我要永遠(yuǎn)居中</div> ??<div?style="text-align:?center;?margin:?0?auto;?height:?5000px;?background-color:?red"></div> ??<script?type="text/javascript"> ????function?getClientWidth() ????{ ??????var?clientWidth=0; ??????if(document.body.clientWidth&&document.documentElement.clientWidth) ??????{ ????????clientWidth?=?(document.body.clientWidth<document.documentElement.clientWidth)?document.body.clientWidth:document.documentElement.clientWidth; ??????} ??????else ??????{ ????????clientWidth?=?(document.body.clientWidth>document.documentElement.clientWidth)?document.body.clientWidth:document.documentElement.clientWidth; ??????} ??????return?clientWidth; ????} ????function?getClientHeight() ????{ ??????var?clientHeight=0; ??????if(document.body.clientHeight&&document.documentElement.clientHeight) ??????{ ????????clientHeight?=?(document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight; ??????} ??????else ??????{ ????????clientHeight?=?(document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight; ??????} ??????return?clientHeight; ????} ????var?d1?=?document.getElementById("d1"); ????d1.style.left?=?getClientWidth()/2?-?50?+?"px"; ????d1.style.top?=?getClientHeight()/2?-?50?+?"px"; ??</script> ??<!--?若果要使用Boostrap的js插件,必須先調(diào)入jQuery?--> ??<script?src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script> ??<!--?包括所有bootstrap的js插件或者可以根據(jù)需要使用的js插件調(diào)用 --> ??<script?src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </body> </html>
貌似沒有,只能自己先寫
position:?Fixed;
自己寫啊text-align:center;vertical-align: middle;
text-align: center;
margin: 0 auto;
好像是需要用jquery動態(tài)獲取屏幕的高度。
看了下源代碼,沒找到,sad~ ?那么問題又來了,怎么寫這樣一個類呢?
好像沒有
舉報
告訴你使用Bootstrap,并且能夠獨(dú)立定制出適合自己的Bootstrap
2 回答怎么讓彈出框上下左右都居中啊
1 回答bootstrap的下拉菜單可不可以鼠標(biāo)放上去 就顯示下拉內(nèi)容
2 回答bootstrap中一個元素達(dá)到設(shè)置的闕值的時候,如何讓這個元素消失(不顯示),bootstrap有沒有提供相應(yīng)的解決方法
3 回答在myeclipse中可以引用bootstrap么?
2 回答bootstrap中 p元素默認(rèn)的只有一個下邊距啊
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-10-11
貌似沒有,只能自己先寫
2016-11-28
自己寫啊text-align:center;vertical-align: middle;
2016-09-14
text-align: center;
margin: 0 auto;
2016-04-15
好像是需要用jquery動態(tài)獲取屏幕的高度。
2016-04-15
看了下源代碼,沒找到,sad~ ?那么問題又來了,怎么寫這樣一個類呢?
2016-04-15
好像沒有