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

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

無法在 Flexbox 中將 div 居中

無法在 Flexbox 中將 div 居中

蕪湖不蕪 2023-12-11 10:10:51
嗨,所以我只需要一些幫助flexbox,我查看了其他人,甚至復(fù)制了那里的代碼進行測試,但由于某種原因它不起作用。我正在嘗試讓div內(nèi)容在網(wǎng)站的頂部中心對齊。這是我當(dāng)前的代碼,索引.html<div class="header">   <div class="headerContent">    <h1>TEST<h1>  </div></div樣式.csshtml {   display: flex;}.header {  display: flex;  align-items: center;  justify-content: center;  flex-direction: column;} .headerContent {    background-color: #2C374C;     width: 100%;   justify-content: center;}
查看完整描述

3 回答

?
九州編程

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

看來你正在做正確的事情,但在錯誤的元素上。當(dāng)它是子容器時,您將.headerid 視為父容器。


在這種情況下,容器層次結(jié)構(gòu)如下html-> header->.headerContent


因此,要居中,header您需要對其父級采取行動。將其想象為父母向其孩子發(fā)出命令(字面意思)。


html { 

  display: flex;

  justify-content: center;

}

通過這樣做,父組件正在證明其內(nèi)容(子組件)


我還建議不要使用 html 創(chuàng)建另一個 div 容器作為標(biāo)頭 div 的父容器,如下所示


.headerContainer { 

  display: flex;

  justify-content: center;

  background-color: red

}

.header {

  display: flex;

}

 .headerContent {

    background-color: #2C374C; 

    width: 100%;

}

    <div class="headerContainer">

      <div class="header"> 

  <div class="headerContent">

    <h1>TEST<h1>

  </div>

 </div>

    </div>


查看完整回答
反對 回復(fù) 2023-12-11
?
子衿沉夜

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

我想就像這樣


.header {

  width: 100%;

}

.headerContent {

  background-color: #2c374c;

  width: 100%;

  display: flex;

  justify-content: center;

  align-items: center;

  flex-direction: column;

}

<html>

  <link rel="stylesheet" href="style.css" />

  <div class="header">

    <div class="headerContent">

      <h1>Test</h1>

    </div>

  </div>

</html>


查看完整回答
反對 回復(fù) 2023-12-11
?
眼眸繁星

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

當(dāng)您使用flex-direction: column;, 來水平居中時,請使用align-items: center;而不是justify-content: center;


您還設(shè)置了一個height屬性。


例子:


.header{

  display: flex;

  height: 300px;

  justify-content: center;

  align-items: center;

  

  background: red

}

<header class="header">

  <div>centered</div>

</header>


查看完整回答
反對 回復(fù) 2023-12-11
  • 3 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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