網站首頁 編程語言 正文
文章目錄
- 一、 未知高度元素水平居中、垂直居中的實現方式
- 1-1 絕對定位 transform: translate(-50%,-50%)
- 1-2 css3的flex布局
- 二、 實現圖片垂直居中
- 2-1 flex實現圖片垂直居中
- 2-2 絕對定位實現垂直居中
一、 未知高度元素水平居中、垂直居中的實現方式
1-1 絕對定位 transform: translate(-50%,-50%)
.wrap {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
1-2 css3的flex布局
.wrap {
display: flex;
justify-content: center;
}
.child {
align-self: center;
}
二、 實現圖片垂直居中
2-1 flex實現圖片垂直居中
<div class="flexbox">
<img src="1.jpg" alt="">
</div>
<style>
.flexbox{
width: 300px;
height: 250px;
background:#fff;
display: flex;
align-items: center
}
.flexbox img{
width: 100px;
height: 100px;
align-items: center;
}
</style>
2-2 絕對定位實現垂直居中
<div class="posdiv">
<img src="1.jpg" alt="">
</div>
<style>
.posdiv{
width: 300px;
height: 250px;
background: #fff;
position: relative;
margin:0 auto
}
.posdiv img{
width: 100px;
position: absolute;
top: 50%;
margin-top: -50px;}
</style>
原文鏈接:https://blog.csdn.net/hannah2233/article/details/125658610
相關推薦
- 2023-12-14 如何查看瀏覽器內核版本
- 2022-11-01 如何將asp.net?core程序部署到Linux服務器_實用技巧
- 2023-02-01 Python局部函數及用法詳解(含nonlocal關鍵字)_python
- 2022-04-11 架構思維之緩存雪崩的災難復盤_相關技巧
- 2022-11-05 一篇文章說清楚?go?get?使用私有庫的方法_Golang
- 2022-09-01 C#實現簡單工廠模式_C#教程
- 2022-05-21 云原生自動化應用于docker倉庫私有憑據secret創建_docker
- 2022-03-14 spring junit 做單元測試,報 Failed to load ApplicationCon
- 最近更新
-
- 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同步修改后的遠程分支