主頁
CSS
CSS 對齊
Tryit: 居中與行高
執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> .center { line-height: 200px; height: 200px; border: 3px solid green; text-align: center; } .center p { line-height: 1.5; display: inline-block; vertical-align: middle; } </style> </head> <body> <h2>Center with line-height</h2> <p>In this example, we use the line-height property with a value that is equal to the height property to center the div element:</p> <div class="center"> <p>I am vertically and horizontally centered.</p> </div> </body> </html>