亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何在引導中垂直對齊容器

如何在引導中垂直對齊容器

桃花長相依 2019-07-05 09:45:43
如何在引導中垂直對齊容器我正在尋找一種垂直中心對齊的方法container內部的divjumbotron并將其設置在頁面的中間。這個.jumbotron必須適應整個屏幕的高度和寬度,所以我使用了這個CSS。.jumbotron{   heght:100%;   width:100%;}這個.containerdiv的寬度為1025px并且應該在頁面的中間(垂直中心)。.container{   width:1025px;}.jumbotron .container {   max-width: 100%;}我的HTML就像<div class="jumbotron">         <div class="container text-center">             <h1>The easiest and powerful way</h1>             <div class="row">                 <div class="col-md-7">                      <div class="top-bg"></div>                 </div>                 <div class="col-md-5 iPhone-features" style="margin-left:-25px;">                     <ul class="top-features">                         <li>                             <span><i class="fa fa-random simple_bg top-features-bg"></i></span>                             <p><strong>Redirect</strong><br>Visitors where they converts more.</p>                         </li>                         <li>                             <span><i class="fa fa-cogs simple_bg top-features-bg"></i></span>                             <p><strong>Track</strong><br>Views, Clicks and Conversions.</p>                         </li>                         <li>                             <span><i class="fa fa-check simple_bg top-features-bg"></i></span>                             <p><strong>Check</strong><br>Constantly the status of your links.</p>                         </li>                                      </ul>                 </div>             </div>         </div>     </div>因此,我希望這個頁面能夠適應屏幕的高度和寬度,以及容器垂直中心到巨無霸。我怎樣才能做到呢?
查看完整描述

3 回答

?
德瑪西亞99

TA貢獻1770條經驗 獲得超3個贊

柔性箱方式

垂直對準現在非常簡單,通過使用柔性盒布局..現在,這個方法在寬范圍除了InternetExplorer 8和9。因此,我們需要使用一些hack/聚填充物不同方法第IE8/9號文件。

在下面的文章中,我將向您展示如何僅在3行文本(不考慮舊的Flexbox語法).

注:最好使用一個額外的類,而不是修改.jumbotron實現垂直對齊。我會用vertical-center例如類名。

這里的例子 (A)(關于jsbin).

<div class="jumbotron vertical-center"> <!-- 
                      ^--- Added class  -->
  <div class="container">
    ...  </div></div>
.vertical-center {
  min-height: 100%;  /* Fallback for browsers do NOT support vh unit */
  min-height: 100vh; /* These two lines are counted as one :-)       */

  display: flex;
  align-items: center;}

重要注記(在演示中考慮):

  1. 百分比值.的值heightmin-height屬性相對于height因此,應該指定height顯式的父母。

  2. 供應商前綴/舊的Flexbox語法由于簡潔而在已發布的代碼段中省略,但在線示例中存在。

  3. 在一些舊的web瀏覽器中,比如Firefox 9(其中我測試過)撓性容器-.vertical-center在這種情況下-將不會占用父級內部可用的空間,因此我們需要指定width財產,如:width: 100%.

  4. 另外,在上面提到的一些web瀏覽器中,FLEX項目-.container在這種情況下-可能不會出現在中心水平。似乎申請的左/右marginauto對彈性物品沒有任何影響。
    因此,我們需要通過box-pack / justify-content.

有關列的更多詳細信息和/或垂直對齊,請參考以下主題:


舊式web瀏覽器的傳統方式

這是我在回答這個問題時寫的舊答案。討論了這種方法。這里它應該也適用于InternetExplorer 8和9。我會簡單地解釋一下:

在內聯流中,內聯級別元素可以通過以下方式垂直對齊到中間。vertical-align: middle申報。規格W3C:

中間
將方框的垂直中點與父框的基線加上父框x高度的一半對齊。

如果父母-.vertical-center元素在本例中有一個顯式height,如果我們有一個完全相同的子元素height對于父母,我們可以若要移動父級的基線,請執行以下操作到全高度孩子的中點,并令人驚訝地使我們想要的流子-.container-垂直對中。

聚在一起

盡管如此,我們可以在.vertical-center通過::before::after元素,并更改默認值。display類型和另一個孩子,.containerinline-block.

然后使用vertical-align: middle;若要垂直對齊內聯元素,請執行以下操作。

給你:

<div class="jumbotron vertical-center">
  <div class="container">
    ...  </div></div>
.vertical-center {
  height:100%;
  width:100%;

  text-align: center;  /* align the inline(-block) elements horizontally */
  font: 0/0 a;         /* remove the gap between inline(-block) elements */}.vertical-center:before {    
  /* create a full-height inline block pseudo=element */
  content: " ";
  display: inline-block;
  vertical-align: middle;    /* vertical alignment of the inline element */
  height: 100%;}.vertical-center > .container {
  max-width: 100%;

  display: inline-block;
  vertical-align: middle;  /* vertical alignment of the inline element */
                           /* reset the font property */
  font: 16px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;}

工作演示.

此外,為了防止超小型屏幕中出現意外問題,可以將偽元素的高度重置為auto0或改變其display輸入到none如有必要,請:

@media (max-width: 768px) {
  .vertical-center:before {
    height: auto;
    /* Or */
    display: none;
  }}

更新演示

還有一件事:

如果有footer/header容器周圍的部分,最好正確地定位元素(relativeabsolute?由你決定)增加一個更高的z-index有價值(為保證)使他們永遠處于其他人的頂端。


查看完整回答
反對 回復 2019-07-05
?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

添加Bootstrap.css,然后將其添加到CSS中


   

html, body{height:100%; margin:0;padding:0}

 

.container-fluid{

  height:100%;

  display:table;

  width: 100%;

  padding: 0;

}

 

.row-fluid {height: 100%; display:table-cell; vertical-align: middle;}

 

 


.centering {

  float:none;

  margin:0 auto;

}

Now call in your page 


<div class="container-fluid">

    <div class="row-fluid">

        <div class="centering text-center">

           Am in the Center Now :-)

        </div>

    </div>

</div>


查看完整回答
反對 回復 2019-07-05
  • 3 回答
  • 0 關注
  • 627 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號