可以通过设置div的display属性为flex,再利用justify-content和align-items属性来实现非字体元素的居中。

例如,以下代码可以将div中的图片和文字都居中显示:

<div style="display: flex; justify-content: center; align-items: center;">
  <img src="example.jpg" alt="example" style="margin-right: 10px;">
  <span>这是一个例子</span>
</div>

其中,display: flex将div设置为flex布局,justify-content: center将内部元素水平居中,align-items: center将内部元素垂直居中。同时,通过为图片设置margin-right属性来调整图片和文字之间的间距。

div内部非字体元素居中

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

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