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,
- How to remove old 404 pages ulrs from Google crawler
- W3 HTML validator warning Unable to Determine Parse Mode
- Comprehensive 256 Ascii code table with Html Hex IBM Microsoft Key
- Align html element at the center of page vertically and horizontally
- HTML Images - Attributes and Formats
- 9 Border to DIV Element in HTML Examples
- Create HTML button that looks like a href hyperlink
- What is the doctype for HTML5?
- Simple Crossword Puzzle example using Pure HTML, CSS and JavaScript
- How to make a div tag clickable
- The author stylesheet specified in tag script is too long - document contains 21759 bytes whereas the limit is 10000 bytes
- W3 : character data is not allowed here html validation error
- How to set background color in HTML page?
- Auto Refresh Webpage after every x Second or Minute using Meta Tag?
- Default speed of Marquee tag : SCROLLAMOUNT
- Get HTML table td, tr or th inner content value with id or name attribute
- How to add multiple spaces between html page text
- Chessboard with pieces using pure HTML and CSS
- How to turn off autocomplete in input fields in HTML Form
- remove div vertical scroll
- Fibonacci series from 1 to 500 table
- Remove Html head and body tags from ckeditor source
- reCaptcha Verification expired. Check the checkbox again
- HTML5 CSS3 Color Codes List
- All directional arrows codes for HTML
More Posts:
- Fix Generics: error unexpected type required: class found: type parameter - Java
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0 - Java
- How to add a Task List to Quick View Menu in SharePoint Online Site - SharePoint
- Install GitHub Command Line Tool on Mac - Git
- How to Write Code in Windows Notepad - Windows
- Working with Bluetooth on Mac Terminal using blueutil Commands - MacOS
- How to change Android EditText Cursor Color - Android
- Ubuntu: How to set Environment Variable - Ubuntu