To align any element of HTML (div, image tag, links, paragraph tag, spans, etc) or nested elements at the middle of the page i.e. at the center both vertically and horizontally we need to use the following CSS attributes to the parent element.
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-align:center;
width: 200px;
height: 20px;
Example:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.parent {
color:#444444;
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-align:center;
width: 200px;
height: 20px;
}
</style>
</head>
<body>
<h1>HTML element at the middle of the page</h1>
<div class="parent">
<h2>Hello world!!</h2>
</div>
</body>
</html>
More Posts related to Html,
- Remove Html head and body tags from ckeditor source
- Default speed of Marquee tag : SCROLLAMOUNT
- Align html element at the center of page vertically and horizontally
- HTML, HTML5. CSS, CSS3 Color Codes 2020
- How to add multiple spaces between html page text
- Force convert HTML text input to upper case
- Obsolete marquee element alternatives html5
- How to set background color in HTML page?
- Base 64 Index, Character and Binary Table
- Hyperlink in html (anchor tag) without a underline
- How to remove old 404 pages ulrs from Google crawler
- W3 HTML validator warning Unable to Determine Parse Mode
- Get HTML table td, tr or th inner content value with id or name attribute
- How to word wrap in HTML
- reCaptcha Verification expired. Check the checkbox again
- Adding Sub Headings to Bootstrap Header tags
- Chessboard with pieces using pure HTML and CSS
- How to turn off autocomplete in input fields in HTML Form
- All directional arrows codes for HTML
- Fibonacci series from 1 to 500 table
- W3 : character data is not allowed here html validation error
- How to make a div tag clickable
- Comprehensive 256 Ascii code table with Html Hex IBM Microsoft Key
- HTML5 HELLO WORLD Example
- Create HTML button that looks like a href hyperlink
More Posts:
- How to Gzip a file directory on Mac OS X using Terminal Command - Mac-OS-X
- [Solved] Mic not working on iPhone 7 after iOS 14 upgrade - Apple
- Setting up Cloud feature with Notepad++ - NotepadPlusPlus
- Find Mac version using terminal command - MacOS
- Unable to connect to the Internet : Google Chrome - Chrome
- Enable Spellcheck in eclipse workspace - Eclipse
- ls command sort by file size [Linix/UNIX/macOS/bash] - Linux
- How to enable line numbers in IntelliJ - HowTos