[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Center text in div

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

Thanks

Allen in Dallas

<HTML>
<HEAD>
<title> JS Date </title>
<style type="text/css">
div {font-family:arial; color:sienna;}
</style>
</HEAD onload jloop()>
<BODY>
<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();
document.write(d);

</script>
</div>
</div>
</BODY>
</HTML>
0
Allen Pitts
Asked:
Allen Pitts
1 Solution
 
GaryCommented:
Use
text-align:center

margin is for positioning an element not text
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now