css 利用 position + margin 實現固定盒子橫向縱向居中的方法
發布時間:2020-12-23 14:32:25 作者:352328759
我要評論

這篇文章主要介紹了css 利用 position + margin 實現固定盒子橫向縱向居中的方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
margin:auto; + position: absolute; 上下左右:0
一看 demo 就懂的啦
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <title>利用 position + margin 實現固定盒子橫向縱向居中</title> <style> body * { outline: 1px #ff0000 solid; } .father { width: 500px; height: 300px; position: relative; } .father .son { width: 180px; height: 140px; /* */ position: absolute; right: 0; bottom: 0; top: 0; left: 0; margin: auto; } </style> </head> <body> <div class="father"> <div class="son">margin:auto + 上下左右:0</div> </div> </body> </html>
//end
到此這篇關于css 利用 position + margin 實現固定盒子橫向縱向居中的方法的文章就介紹到這了,更多相關css固定盒子橫向縱向居中內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章,希望大家以后多多支持腳本之家!
相關文章
CSS 同級元素position:fixed和margin-top共同使用的問題
這篇文章主要介紹了CSS 同級元素position:fixed和margin-top共同使用的問題的相關資料,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-13- 這篇文章主要介紹了使用CSS實現盒子水平垂直居中的方法(8種),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來2020-11-11
- 這篇文章主要介紹了CSS盒子居中的常用的幾種方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學2020-03-31
最新評論