Detailed explanation of flex and position compatibility mining notes

Detailed explanation of flex and position compatibility mining notes

Today I had some free time to write a website for my own homepage, which is compatible with all browsers (mainly IE 9 and above and Chrome). There is a previous problem which is also a very common problem. Since I have encountered it, I might as well record it. Let’s look at the question directly

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document Title</title>
</head>
<body>
	<div class="aaa">
      <div>
        
      </div>
  </div>
</body>
</html>
<style>
.aaa{
 	 width:700px;
 	 height:500px;
 	 position:absolute;
	 background-color:red;
  	 display: flex;
  	 align-items: center;
}
.aaa div{
  	height: 200px;
  	width:200px;
  	position: absolute;
 	background-color:yellow;		
}
</style>

Prerequisite: The sub-element needs to be centered horizontally, but position:absolute is required in the vertical direction. If position:relative or其他is required, it is the same in ie or chrome , and子元素width中點is used as the base point.

In IE: The properties in the parent container: display: flex;align-items: center; are horizontally centered, but the base point is左上角, as shown in the figure below. If you want to center it horizontally, you need to add: transform:translateX(-50%) , which means左移動自身width的50% . The advantage is that it does not matter whether you know the width of the element or not.

Chrome: Properties in the parent container: display: flex;align-items: center; directly center the child element horizontally, with the base point being子元素width的中點, rather than ie中的左上角;

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Write your HTML like this to make your code more compatible

>>:  How to modify the default storage location of Docker images (solution)

Recommend

Nginx configuration SSL and WSS steps introduction

Table of contents Preface 1. Nginx installation 1...

Overview and differences between html inline elements and html block-level elements

Block-level element features : •Always occupies a ...

HTML form_PowerNode Java Academy

1. Form 1. The role of the form HTML forms are us...

Introducing multiple custom fonts in CSS3

Today I found a problem in HTML. There are many d...

Implementation of building custom images with Dockerfile

Table of contents Preface Introduction to Dockerf...

MySQL inspection script (must read)

As shown below: #!/usr/bin/env python3.5 import p...

How to implement vue page jump

1. this.$router.push() 1. Vue <template> &l...

Implementation of webpack-dev-server to build a local server

Table of contents Preface webpack-deb-server webp...

CSS3 transition to achieve underline example code

This article introduces the sample code of CSS3 t...

How to install tomcat8 in docker

1. Install tomcat8 with docker 1. Find the tomcat...

About the problem of writing plugins for mounting DOM in vue3

Compared with vue2, vue3 has an additional concep...

The combination and difference between ENTRYPOINT and CMD in dockerfile

In the previous article [Detailed explanation of ...

How to use fdisk to partition disk in Linux

Commonly used commands for Linux partitions: fdis...

Tutorial on installing mysql under centos7

Recently, I plan to deploy a cloud disk on my hom...