網站首頁 編程語言 正文
1、flex布局方法:當前div的父級添加flex css樣式
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
2、絕對定位方法:不確定當前div的寬度和高度,采用 transform: translate(-50%,-50%); 當前div的父級添加相對定位(position: relative;)
background: green;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
3、絕對定位方法:確定了當前div的寬度,margin值為當前div寬度一半的負值
.father {
background: red;
position: relative;
width: 500px;
height: 500px;
}
.son {
width: 200px;
height: 200px;
background: green;
position: absolute;
left: 50%;
top: 50%;
margin-left: -100px;
margin-top: -100px;
}
4、絕對定位方法:絕對定位下top left right bottom 都設置0 ,margin設置為auto
.father {
background: red;
position: relative;
width: 500px;
height: 500px;
}
.son {
width: 200px;
height: 200px;
background: green;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
margin: auto;
}
5、table-cell實現水平垂直居中: table-cell middle center組合使用(子元素不能是塊級元素) 子div只能不能是塊狀元素,否則只能垂直居中,無法水平居中
/*table-cell、vertical-align、text-align組合使用*/
.father {
width: 500px;
height: 500px;
display: table-cell;
vertical-align: middle;
text-align: center;
background-color: red;
}
.son {
width: 200px;
height: 200px;
background-color: green;
display: inline-block;
原文鏈接:https://blog.csdn.net/study_way/article/details/109004761
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-07-22 Qt鍵盤事件和鼠標事件、定時器小實例詳解
- 2022-08-03 C++中TinyXML讀取xml文件用法詳解_C 語言
- 2022-05-04 ?Python?中?logging?模塊使用詳情_python
- 2022-11-07 一文教會你用python連接并簡單操作SQLserver數據庫_python
- 2023-01-15 Python?pytest.main()運行測試用例_python
- 2022-04-25 Entity?Framework?Core中執行SQL語句和存儲過程的方法介紹_實用技巧
- 2022-03-16 C#語言主要語言區域_C#教程
- 2022-06-04 python對文檔中元素刪除,替換操作_python
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支