Require
analyze
Code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> body{ padding: 0; margin: 0; } #box{ width: 50%; /* Center the div */ position: relative; transform: translate(50%, 25%); /* */ /* Here we solve the problem that the div height is half of the body width and the text is vertically centered*/ padding-top: 25%; padding-bottom: 25%; line-height: 0; text-align: center; /* */ background-color: #111; color: #fff; } </style> </head> <body> <div id="box"> box123 </div> </body> </html> Effect This is the end of this article about how to use CSS to completely center a div without setting a height. For more information about how to use CSS to completely center a div without setting a height, 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! |
<<: JavaScript error handling try..catch...finally + covers throw+TypeError+RangeError
>>: Detailed explanation of Web front-end performance optimization: resource merging and compression
1. Compile proto Create a new proto folder under ...
Table of contents rc.local method chkconfig metho...
in conclusion % of width: defines the percentage ...
Table of contents 1. Concept 1.1 What are errors ...
Copy code The code is as follows: <span style=...
cause The way to import external files into a min...
The detailed process of installing python3.7.0 on...
Table of contents background What is the Metavers...
In web front-end development, it is inevitable to ...
1. Set the parent container to a table and the ch...
background The Agile model is widely used, and te...
Table of contents Early creation method Factory P...
Lists for organizing data After learning so many ...
The a tag is mainly used to implement page jump, ...
Use vite to build a vue3 project You can quickly ...