margin:auto; + position: absolute; up, down, left, and right:0 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <title>Use position + margin to fix the box horizontally and vertically</title> <style> body * { outline: 1px #ff0000 solid; } .father { width: 500px; height: 300px; position: relative; } .father .son { width: 180px; height: 140px; /* */ position: absolute; right: 0; bottom: 0; top: 0; left: 0; margin: auto; } </style> </head> <body> <div class="father"> <div class="son">margin:auto + up, down, left, and right:0</div> </div> </body> </html> //end This is the end of this article about how to use position + margin in CSS to achieve horizontal and vertical centering of a fixed box. For more relevant content on horizontal and vertical centering of a fixed box in CSS, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Docker deploys Mysql, .Net6, Sqlserver and other containers
>>: Sublime Text - Recommended method for setting browser shortcut keys
Overview For small and medium-sized projects, joi...
When using Docker containers, it is more convenie...
This article introduces MySQL string interception...
The <canvas> element is designed for client...
Building an image is a very important process in ...
This article uses examples to describe the creati...
What is k3d? k3d is a small program for running a...
When Mysql associates two tables, an error messag...
Windows Server 2012 and Windows Server 2008 diffe...
It is mainly a CSS style control and a META tag; C...
The role of init_connect init_connect is usually ...
This article takes the health reporting system of...
When faced with a SQL statement that is not optim...
Table of contents 1. Communication between father...
Why do we say “usually 1em=16px”? The default tex...