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
<br />Choose the most practical one to talk ...
Table of contents 1. Download 2. Installation and...
This article mainly introduces the relevant solut...
Preface As we all know, JavaScript is single-thre...
Jellyka BeesAntique Handwriting [ank]* Jellyka Cut...
Using the CSS3 border-image property, you can set...
I feel that the explanation of this.$set on the I...
1. Drop-down list example The code is as follows:...
When the author was using MySQL to add a user, he...
When using XAML layout, sometimes in order to make...
1. The role of index Generally speaking, an index...
Table of contents Proper use of indexes 1. Disadv...
I'll record the problems I encountered during...
This article example shares the specific code of ...
html <!DOCTYPE html> <html lang="en...