当前位置:网站首页>[notes] summarize common horizontal and vertical centering methods
[notes] summarize common horizontal and vertical centering methods
2022-06-13 03:59:00 【Smoothzjc】
When reviewing the horizontal and vertical center, I found that I had forgotten
So write a note and write it down
As long as it involves CSS There is no way around the positioning problem , Especially when the box is centered . Centring is divided into horizontal centring and vertical centring , There are several ways to do this , I'll list them one by one .
Horizontal center
- inline Elements :text-align: center
- block Elements :margin: 0 auto
- absolute Elements :left: 50% + margin-left negative ( The value is half the width of the element )
- absolute Elements :left: 50% + transform: translateX(-50%)
Vertical center
- inline Elements :line-height The value is equal to the height value
- absolute Elements :top:50%+margin-top negative ( The value is half the height of the element )
- absolute Elements :top:50%+transform: translateY(-50%)
- absolute Elements : Have a fixed width and height +top,left,bottom,right=0 + margin:auto
Horizontal vertical center
Is the above level in the middle + Vertically centered together
Here are some common examples :
Positioning yes relative Inside the box absolute The box :
top: 50%;left: 50%;transform: translate(-50%,-50%);

Know the width and height of the box
top: 50%;left: 50%;
add
margin-left negative ( The value is half the width of the element );margin-top negative ( The value is half the height of the element )

Positioning yes relative Inside the box absolute The box has a fixed width and height :
top,left,bottom,right=0 + margin:auto

CSS3 Elastic layout (flex)
If you use CSS3 Flexible layout (flex) Words , The problem will become much easier . Use CSS3 The flexible layout of is very simple , Just set the parent element to
display:flex // flex Layout
align-items:center;// The elements are horizontally centered
justify-content:center;// The elements are centered vertically


You are welcome to ask questions in the comment area
If you think the article is helpful to you, you might as well like it before you go ~
边栏推荐
- Lambda end operation count
- 单片机外设介绍:温度传感器 DS18B20
- 5G China unicom 直放站 网管协议 实时性要求
- [test development] fundamentals of software testing
- 单片机信号发生器程序
- Jumpserver installation
- Lambda终结操作count
- ET框架-22 创建ServerInfo实体及事件
- MCU: EEPROM multi byte read / write operation sequence
- Principle, composition and functions of sensors of Dajiang UAV flight control system
猜你喜欢

2022 spring semester summary

环评图件制作-数据处理+图件制作

Real time question answering of single chip microcomputer / embedded system

大五人格学习记录

Synching build your own synchronization cloud

大疆无人机飞控系统的原理、组成及各传感器的作用

单片机信号发生器程序
![[web] cookies and sessions](/img/00/b10a9f4ae918afe5d032a9af20a49c.png)
[web] cookies and sessions

【 développement d'essais 】 sélénium d'essais automatisés (Ⅲ) - - analyse du cadre unitest

无人机避障四种常见技术中,为何大疆首选双目视觉
随机推荐
GoFrame第五天
手机私有充电协议解读
环评图件制作-数据处理+图件制作
Fundamentals of robot obstacle avoidance system
Lambda终结操作查找与匹配findFirst
Solution to failure to download files by wechat scanning QR code
【测试开发】自动化测试selenium(二)——webdriver常用的API
[笔记]vs2015 编写汇编masm32之使用MASM32库
Redis-HyperLogLog-基数统计算法
单片机:A/D(模数转换)的主要指标
[Yugong series] June 2022 Net architecture class 081 API customization task of distributed middleware schedulemaster
Binocular vision -- creating an "optimal solution" for outdoor obstacle avoidance
[interview review] update from time to time for personal use
Principle and control program of single chip microcomputer serial port communication
Talking about the wavelength of laser radar
Single chip microcomputer: pcf8591 application program
LVS four layer load balancing cluster (4) main methods of load balancing
单片机:A/D 差分输入信号
干预分析 + 伪回归
MCU: EEPROM multi byte read / write operation sequence