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

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

在flexbox中的圖像上居中文本

在flexbox中的圖像上居中文本

心有法竹 2019-12-02 08:04:00
在flexbox中的圖像上居中文本如何將文本居中對齊<img>優(yōu)選使用FlexBox?body {   margin: 0px;}.height-100vh {   height: 100vh;}.center-aligned {   display: box;   display: flex;   box-align: center;   align-items: center;   box-pack: center;   justify-content: center;}.background-image {   position: relative;}.text {   position: absolute;}<section class="height-100vh center-aligned">   <img class="background-image" src="http://vignette2.wikia.nocookie.net/uncyclopedia/images/f/f8/Stand-out-in-the-crowd-300x300.jpg" />   <div class="text">SOME TEXT</div></section>
查看完整描述

3 回答

?
一只甜甜圈

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

要將文本居中于圖像上,您不需要flexbox。只需使用CSS定位屬性。

.height-100vh {
    height: 100vh;
    position: relative;               /* establish nearest positioned ancestor for
                                         absolute positioning */}.text {
    position: absolute;  
    left: 50%;                        /* horizontal alignment */
    top: 50%;                         /* vertical alignment */
    transform: translate(-50%, -50%); /* precise centering; see link below */}

修改了Codepen

上面的代碼將文本在圖像上垂直和水平居中:





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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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