尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

块级居中、行内居中、绝对定位居中 多种实现方案

块级居中、行内居中、绝对定位居中 多种实现方案 1. 行内/行内块元素水平居中给父元素设置text-align: center适用文字、span、a、img、input、button 等。2. 块级元素水平居中方案一margin 居中常规首选元素定宽时margin: 0 auto方案二Flex 居中不定宽通用父 { display: flex; justify-content: center; }3. 垂直居中方案大全1单行文本垂直居中height line-height2Flex 万能居中推荐父 { display: flex; justify-content: center; align-items: center; }3绝对定位居中不定高宽通用父 { position: relative; } 子 { position: absolute; left: 0; right: 0; top: 0; bottom: 0; margin: auto; }4transform 居中子 { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); }
返回列表