欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CSS中使用inline-block來進行居中的示例

  發(fā)布時間:2015-07-15 16:48:09   作者:佚名   我要評論
這篇文章主要介紹了CSS中使用inline-block來進行居中的示例,使用的時候注意一下容器的寬度,需要的朋友可以參考下

迫切需要的方法:inline-block法居中。基本方法是使用 display: inline-block, vertical-align: middle樣式和偽元素讓內(nèi)容塊在容器中居中。我的實現(xiàn)用到了幾個在其他地方見不到的新技巧解決了一些問題。

  內(nèi)容區(qū)聲明的寬度不能大于容器的100% 減去0.25em的寬度。就像一段帶有長文本的區(qū)域。不然,內(nèi)容區(qū)域會被推到頂端,這就是使用:after偽類的原因。使用:before偽類則會讓元素有100%的大小!
2015715165035528.jpg (607×401)

如果內(nèi)容塊需要盡可能大地占用水平空間,可以為大容器加上max-width: 99%;樣式,或者考慮瀏覽器和容器寬度的情況下使用max-width: calc(100% – 0.25em) 樣式。

  這種方法和table-cell的大多數(shù)好處相同,不過最初我放棄了這個方法,因為它更像是hack。不管這一點的話,瀏覽器支持很不錯,而且也被證實是很流行的方法。

  HTML:
 

XML/HTML Code復制內(nèi)容到剪貼板
  1. <div class="Center-Container is-Inline">  
  2.   <div class="Center-Block">  
  3.     <!-- CONTENT -->  
  4.   </div>  
  5. </div>  

  CSS:
 

CSS Code復制內(nèi)容到剪貼板
  1. .Center-Container.is-Inline {    
  2.   text-aligncenter;   
  3.   overflow: <span style="width: auto; height: auto; float: none;" id="7_nwp"><a style="text-decoration: none;" mpid="7" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=2d6719abf210fdd5&k=auto&k0=auto&kdi0=0&luki=9&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=d5fd10f2ab19672d&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F3058%2Ehtml&urlid=0" id="7_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">auto</span></a></span>;   
  4. }   
  5.     
  6. .Center-Container.is-Inline:after,   
  7. .is-Inline .Center-Block {   
  8.   displayinline-<span style="width: auto; height: auto; float: none;" id="8_nwp"><a style="text-decoration: none;" mpid="8" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=2d6719abf210fdd5&k=block&k0=block&kdi0=0&luki=7&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=d5fd10f2ab19672d&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F3058%2Ehtml&urlid=0" id="8_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">block</span></a></span>;   
  9.   vertical-alignmiddle;   
  10. }   
  11.     
  12. .Center-Container.is-Inline:after {   
  13.   content'';   
  14.   height: 100%;   
  15.   margin-left: -0.25em; /* To offset spacing. May vary by font */  
  16. }   
  17.     
  18. .is-Inline .Center-Block {   
  19.   max-width: 99%; /* Prevents issues with long content causes the content block to be pushed to the top */  
  20.   /* max-width: calc(100% - 0.25em) /* Only for IE9+ */  
  21. }  

  好處:

    內(nèi)容高度可變
    內(nèi)容溢出則能自動撐開父元素高度
    瀏覽器兼容性好,甚至可以調(diào)整支持IE7

  同時注意:

    需要額外容器
    依賴于margin-left: -0.25em的樣式,做到水平居中,需要為不同的字體大小作調(diào)整
    內(nèi)容區(qū)聲明的寬度不能大于容器的100% 減去0.25em的寬度

相關(guān)文章

最新評論