如何从CSS到div中的扶正元素? [重复]

问题描述 投票:-2回答:2

我的样式表中有一个名为gdiv的类,它引用一般的div条件。我可以从gdiv更改文本对齐方式。但无法更改div中所有内容的对齐方式,例如div。如何对齐所有内容?

html css division divide
2个回答
0
投票
我认为将项目与div的中心对齐的最佳方法是使用flexbox

.gdiv { display: flex; /* just to set it to flex box */ justify-content: center; /* to align the items horizontally in the div */ align-items: center; /* to align the items vertically in the div */ } 如果要按DIV的父级对齐DIV本身,则可以在父级中使用此代码;

如果要对齐的是文本,则可以使用:

.gdiv { text-align: center; }

如果您是初学者,我强烈建议您学习CSS中的Flexbox和网格!

-1
投票
display: flex; align-items: center; justify-content: center;
© www.soinside.com 2019 - 2024. All rights reserved.