Center text in div

Posted on 2014-07-17
Last Modified: 2014-07-23
Hello expert,
Have read in about three places that margin left: auto and margin right: auto
will center the text in a div tag. But can't get it to work. Code below


Allen in Dallas

<title> JS Date </title>
<style type="text/css">
div {font-family:arial; color:sienna;}
</HEAD onload jloop()>
<font face="arial" size="4">This writes
the date. <br />It is an example of inline Javascript.</font>

<div style = "background-color: #004280; color: #FFFFFF; position:absolute; top:10px; width: 400px; margin-left: auto; margin-right: auto;">

<script type="text/javascript">

var d=new Date();

Question by:9apit
    1 Comment
    LVL 58

    Accepted Solution


    margin is for positioning an element not text

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
    In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now