Some text

可以使用 CSS 的 flexbox 布局来将非字体元素居中。

首先,在 div 中添加 display:flex; 属性,将其设置为 flex 容器。

然后,使用 justify-content 属性将子元素在主轴上居中对齐,使用 align-items 属性将子元素在交叉轴上居中对齐。

例如:

<div style='display:flex;justify-content:center;align-items:center;'>
  <img src='image.jpg'>
  <p>Some text</p>
</div>

这将使图片和段落都在 div 中水平和垂直居中。

如何使用 Flexbox 将非文字元素居中于 Div 中

原文地址: http://www.cveoy.top/t/topic/nsZX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录