第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

水平和垂直居中DIV

水平和垂直居中DIV

BIG陽 2019-07-26 16:57:55
水平和垂直居中DIV 有沒有辦法垂直和水平地居中DIV,但重要的是,當(dāng)窗口小于內(nèi)容時,內(nèi)容不會被切割 .div必須具有背景顏色和寬度和高度。我總是將div與絕對定位和負(fù)邊距居中,就像在提供的示例中一樣。但它存在的問題是它會削減內(nèi)容。有沒有一種方法可以在沒有這個問題的情況下使div .content居中?我在這里有一個例子:http://jsbin.com/iquviq/1/editCSS:body { margin: 0px; }.background {     width: 100%;     height: 100%;     margin: 0;     padding: 0;     background-color: yellow;}/*  is there a better way than the absolute positioning and negative margin to center the div .content: div with background color a width and a hight?:  */ .content {     width: 200px;     height: 600px;     background-color: blue;     position:absolute;     top:50%;     left:50%;     margin-left:-100px;/* half width*/     margin-top:-300px;/* half height*/}HTML:<div class="background">     <div class="content"> some text </div></div>我的問題不是“如何水平和垂直居中一個元素?”的問題.1我之前曾問過我的問題。(只是查看日期)。2-我的問題非常清楚,并以黑色為條件:“當(dāng)窗口小于內(nèi)容時,內(nèi)容不會被刪除”
查看完整描述

3 回答

?
白板的微信

TA貢獻1883條經(jīng)驗 獲得超3個贊

對于現(xiàn)代瀏覽器

當(dāng)你擁有那種奢侈品。還有flexbox,但在撰寫本文時并沒有廣泛支持。

HTML:

<div class="content">This works with any content</div>

CSS:

.content {
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);}

CodepenJSBin上進一步修補它

對于舊的瀏覽器支持,請查看此線程中的其他位置


查看完整回答
反對 回復(fù) 2019-07-26
  • 3 回答
  • 0 關(guān)注
  • 432 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號