问:块级元素都有哪些?如何让块级元素垂直和水平居中?
七娃博客
679人阅读
块级元素都有哪些?如何让块级元素垂直和水平居中?
常见的块级元素有:h1-h6、hr(水平分割线)、div、p(段落)、ul(无序列表) 、ol(有序列表)、form(表单)
1.绝对定位+margin
*{ position: absolute; width: 100px; height: 100px; left: 0; right: 0; top: 0; bottom: 0; margin: auto; background-color: #fff; }
2.绝对定位+transform
*{ position: absolute; width: 100px; height: 100px; left: 50%; top: 50%; transform: translate(-50%, -50%); background-color: #fff; }
3.Flex弹性布局
*{ display: flex; justify-content: center; align-items: center; }
4.Grid网格布局
*{ /*父级加*/ display: grid; /*对齐元素加*/ justify-self: center; align-self: center; }
主题开源不易,支持一下作者吧!
使用支付宝打赏
使用微信打赏
评论 | 0 条评论
登录之后才可留言,前往登录