html - CSS Flex 显示和段落居中

标签 html css flexbox

我尝试使用 display: flex 而不是 float: left 将段落在 div 中彼此相邻放置,然后我想将此 div 中的所有段落放置到屏幕中心(目前使用 display: flexfloat: left 它们是位于屏幕左侧)

我正在尝试使用:

#div {display: flex; align-items: center;}

在我的 css 中,但它没有起作用。

更有经验的人可以给我一些如何做的提示吗?我一直在摆弄所有不同的属性 - 无论我做什么,文本都会绑定(bind)到左侧。

https://jsfiddle.net/e7bft0eL/

最佳答案

只需添加justifiy-content属性

The justify-content property aligns the flexible container's items when the items do not use all available space on the main-axis (horizontally).

#test{
    display: flex;
    background-color: white;
    align-items: center;
    justify-content: center;
}

jsfiddle

关于html - CSS Flex 显示和段落居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34065959/

相关文章:

HTML CSS 为什么设置的 div 不开始新行

javascript - 将 token 存储到 JS 本地存储安全吗?

javascript - Jquery for循环在每三次循环迭代后写入html

html - 网页下方有很多空白

html - 如何将 flexbox 包装在多行和多列上?

html - 作为 Flexbox 容器的 Flexbox 元素

html - 两张图片,并排响应

html - 什么元素阻止我的宽度属性应用于我的选项卡?

css - 如何仅在 Table Head 上创建圆 Angular

html - Flexbox 不适用于页面响应