If you want to center a text within a <div> element using CSS, then you can make use of the text-align attributes value set as center..
Example:
css code:
<div class="div-eg">Some Text</div>
html code:
.div-eg {
width:400px;
height: 200px;
text-align: center;
background: #eee;
border:1px solid #222
}
Output:
Some Text
-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to CSS,
- Elegant CSS Box Shadows Ideas
- How to Vertically Center Align Text in a Div using CSS Code Example
- How to Center Align Image in Bootstrap
- Change CSS Background Opacity with Examples
- Tutorial : Simple Lightweight Pure CSS based Vertical Navigation Menu
- Simple CSS Grid Example
- CSS: Apply opacity only for div background and not text
- How to create a circular Image using pure CSS Code
- How to place two div elements next to each other
- Responsive Web Design with CSS Media Queries: A Beginner's Tutorial [Updated for 2023]
- Add scroll to div element in HTML Css
- How to make div or text in html unselectable using CSS
- reCAPTCHA Implementation Tutorial
- Set Falling Show on Website for Christmas using Pure CSS Code
- How to set CSS background-Image Property
- List of 32 CSS cursors web developers must know about
- 10 Must Know CSS Border Styles with Examples
- How to make jsfiddle bootstrap ready
- Horizontally Center Align
- Tailwind CSS Hello World Example
- align image at middle of div element
- Only Chessboard using HTML and CSS Code Example
More Posts:
- 33: Python Program to find the current time in India (IST) - Python-Programs
- Where are Plugins Installed in Notepad++ - NotepadPlusPlus
- [fix] Chrome: no listeners for an event URLS_SAFE_CHECK__STATUS_UPDATED - Chrome
- Fix [Fatal Error] :2:6: The processing instruction target matching [xX][mM][lL] is not allowed. - Java
- FileZilla Connection time out Failed to retrieve directory listing - FTP
- How to Select All text in vim/vi editor using Keyboard - Linux
- Microsoft Teams Error code - 6 issue - Teams
- Notepad++ select all above or below lines - NotepadPlusPlus