css居中對齊的設定方法:1、水平居中【text-align:center】;2、水平居中【margin:0 auto】;3、垂直居中【line-height】;4、使用表格,水平、垂直居中;5、彈性佈局,水平、垂直居中。
本教學操作環境:windows7系統、css3版,DELL G3電腦。
css居中對齊的設定方法:
1、text-align:center —— 水平居中
僅對文字、圖片、按鈕等行內元素有效(display設定為inline或inline-block等)進行水平居中
2、margin:0 auto;—— 水平居中
僅水平居中,且對浮動元素定位無效
.father{ width:500px; height:200px; background-color::#f98769; overflow:hidden;//不可缺少否则margin-top不生效 } .son{ width: 100px; height: 100px; margin:50px auto ; background-color: #ff0000; }
3、line-height —— 垂直居中
line-height=height ,僅對一行文字有效
4、使用表格——水平、垂直居中
對td/th的align='center'和valign='middle'兩個屬性可以水平和垂直居中
5、彈性佈局——水平、垂直居中
.father{ display:flex; justity-content:center; align-items:center; } .father{ display:flex; flex-direction:column;//改变主轴为cross axis justity-content:center; }
6、使用display:table-cell —— 水平、垂直居中
對於那些不是表格的元素,我們可以透過display:table-cell 來把它模擬成一個表格單元格
.father{ height:300px; background:#ccc; display:table-cell; /*IE8以上及Chrome、Firefox*/ vertical-align:middle; /*IE8以上及Chrome、Firefox*/ text-align:center; } .son{ display:inline-block;//或是inline }
7、奇淫技巧-子絕父相(已知子元素寬高) —— 水平、垂直居中
.father{ position:relative; } .son{//m、n为子盒子宽、高的一半 position:absolute; left:50%; top:50%; margin-left:-mpx; margin-top:-npx;
8、未知子元素寬高——水平、垂直居中
.father { position:relative; } .son { position:absolute; top:50%; left:50%: transform:translate(-50%,-50%) /*单独设置transform:translateY(-50%);*/ }
9、偽元素法——垂直居中
.father{ position: relative; } .father::before{ content: " "; display: inline-block; height: 100%; width: 1%; vertical-align: middle; } .son{ display: inline-block; vertical-align: middle; }
相關教學推薦:CSS影片教學
以上是css居中對齊怎麼設定的詳細內容。更多資訊請關注PHP中文網其他相關文章!

是的,youshouldlearnbothflexboxandgrid.1)flexboxisidealforone-demensional,flexiblelayoutslikenavigationmenus.2)gridexcelstcelsintwo-dimensional,confffferDesignssignssuchasmagagazineLayouts.3)blosebothenHancesSunHanceSlineHancesLayOutflexibilitibilitibilitibilitibilityAnderibilitibilityAndresponScormentilial anderingStruction

重構自己的代碼看起來是什麼樣的?約翰·瑞亞(John Rhea)挑選了他寫的一個舊的CSS動畫,並介紹了優化它的思維過程。

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatoryand and powerincreatingsmoothcsssanimations.keytricksinclude:1)definingsmoothtransitionsbetnestates,2)使用AnimatingMultatingMultationMultationProperPertiessimultane,3)使用使用4)使用BombingeNtibalibility,4)使用CombanningWiThjavoFofofofoftofofo

CSSCOUNTERSAREDOMANAGEAUTOMANAMBERINGINWEBDESIGNS.1)他們可以使用forterablesofcontents,ListItems,and customnumbering.2)AdvancedsincludenestednumberingSystems.3)挑戰挑戰InclassINCludeBrowsEccerCerceribaliblesibility andperformiballibility andperformissises.4)創造性

使用滾動陰影,尤其是對於移動設備,是克里斯以前涵蓋的一個微妙的UX。傑夫(Geoff)涵蓋了一種使用動畫限制屬性的新方法。這是另一種方式。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

WebStorm Mac版
好用的JavaScript開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SublimeText3 Linux新版
SublimeText3 Linux最新版