Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
如何在 CSS 中将 Div 居中_创想鸟

如何在 CSS 中将 Div 居中

如何在 css 中将 div 居中

弹性盒:

.container {  display: flex;  justify-content: center;  align-items: center;  height: 300px;}

网格

.container {  display: grid;  place-items: center;  height: 300px;}

弹性保证金

.container {  display: flex;  height: 300px;}.centered-div {  margin: auto;}

绝对定位

.container {  position: relative;  height: 300px;}.centered-div {  position: absolute;  top: 50%;  left: 50%;  transform: translate(-50%, -50%);}

自动保证金

.container {  height: 300px;}.centered-div {  width: 200px;  margin: 0 auto;  position: relative;  top: 50%;  transform: translatey(-50%);}

网格模板

.container {  display: grid;  grid-template-columns: 1fr auto 1fr;  grid-template-rows: 1fr auto 1fr;  height: 300px;}.centered-div {  grid-column: 2;  grid-row: 2;}

以上就是如何在 CSS 中将 Div 居中的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1629946.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
什么是 Tailwind CSS?
上一篇 2025年12月24日 12:53:17
CSS 新属性Field-sizing,可以使input 、 textarea和select自适应其内容
下一篇 2025年12月24日 12:53:25

相关推荐

发表回复

登录后才能评论
关注微信