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
Last year, due to project needs, I wrote a crawle...
Overview Databases generally execute multiple tra...
Project scenario: 1. Upload file restrictions Fun...
<iframe src=”test.jsp” width=”100″ height=”50″...
This article shares the specific code of js imita...
This article shares the specific code of js to ac...
Create your first web page in one minute: Let'...
Real-time replication is the most important way t...
Table of contents Filters 01.What is 02. How to d...
Table of contents Preface Dockerfile What is a Do...
Preface MySQL version 8.0.23 adds a new feature: ...
Sometimes we need to control whether HTML elements...
Enable remote access to MySQL By default, MySQL u...
Table of contents Simple CASEWHEN function: This ...
Preface In the previous article Two data types in...