Several ways to vertically and horizontally center in CSS3 with indefinite height and width

Several ways to vertically and horizontally center in CSS3 with indefinite height and width

1. Flex layout

.father {
    display: flex;
    justify-content: center;
    align-items: center;
}

This method is not compatible

2. Position + transform

.son {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

IE9 and below do not support the transform attribute

3. table + table-cell

.father {
    display: table;
}
.son {
    display: table-cell;
    vertical-align: middle;
      text-align: center;
}

4. :before + display:inline-block

.father {
  text-align: center;
}
.father::before {
  content: '';
  display: inline-block;
  height: 100%;
  vertical-align: middle;
}
.son {
  display: inline-block;
}

This concludes this article about several ways to use CSS3 variable height and width vertical and horizontal centering. For more information about CSS3 variable height and width vertical and horizontal centering, please search 123WORDPRESS.COM’s previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  Solutions to browser interpretation differences in size and width and height in CSS

>>:  Complete guide to using iframe without borders or borders (practical experience summary)

Recommend

Usage of MySQL time difference functions TIMESTAMPDIFF and DATEDIFF

Usage of time difference functions TIMESTAMPDIFF ...

JavaScript to achieve time range effect

This article shares the specific code for JavaScr...

How to clear mysql registry

Specific method: 1. Press [ win+r ] to open the r...

Comparison of the efficiency of different methods of deleting files in Linux

Test the efficiency of deleting a large number of...

React Native environment installation process

react-native installation process 1.npx react-nat...

Implementation steps for Docker deployment of SpringBoot applications

Table of contents Preface Dockerfile What is a Do...

Detailed explanation of browser negotiation cache process based on nginx

This article mainly introduces the detailed proce...

Linux uses join -a1 to merge two files

To merge the following two files, merge them toge...

CSS text alignment implementation code

When making forms, we often encounter the situati...

PHP related paths and modification methods in Ubuntu environment

PHP related paths in Ubuntu environment PHP path ...

How to use TypeScript in Vue

introduction In recent years, the call for TypeSc...

Vue implements real-time refresh of the time display in the upper right corner

This article example shares the specific code of ...

Detailed example of using js fetch asynchronous request

Table of contents Understanding Asynchrony fetch(...

Detailed explanation of mysql execution plan id is empty (UNION keyword)

Introduction During the work process, slow querie...