About the invalid line-height setting in CSS Let's write this string of code first: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .head{ height: 100px; text-align: center; line-height: 100px;/* Set the line height to center the font*/ background: #333;/* Set the entire background to black to make it easier to see the font*/ color: red; font:700 18px simsun;/* Set the font*/ } </style> </head> <body> <div class="head"> Hello, Southwest Petroleum University. </div> </body> </html> Then open it in the browser to see the effect: We found that in the vertical direction, the font is not displayed in the middle of the box. Then we put the statement that sets the line height below the statement that sets the font: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .head{ height: 100px; text-align: center; background: #333;/* Set the entire background to black to make it easier to see the font*/ color: red; font:700 18px simsun;/* Set the font*/ line-height: 100px;/* Set line height*/ } </style> </head> <body> <div class="head"> Hello, Southwest Petroleum University. </div> </body> </html> Then open it with your browser: The font successfully jumped to the middle~~~~~ Summary: When setting the line height with CSS, the line-height attribute must be below the font, otherwise it will be invalid! 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. |
<<: JavaScript to achieve magnifying glass effect
>>: Docker installation and deployment example on Linux
I searched online and found that many interviews ...
We have introduced how to create a waterfall layo...
This is a website I imitated when I was self-stud...
Table of contents Preface 1. Reasons: 2. Solution...
Installing XML extension in PHP Linux 1. Enter th...
1. Create users and authorize Creating users and ...
MySQL filtering timing of where conditions and ha...
Overview: The filesystem module is a simple wrapp...
This article shares the specific code for JavaScr...
Primary Key: Keyword: primary key Features: canno...
1. Search mysql in the browser to download and in...
Table of contents Review of Object.defineProperty...
Use HTML to write a dynamic web clock. The code i...
Table of contents JSX environment construction In...
Table of contents 1. Get the value of browser coo...