954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Text Alignment Issue

Hi all,

I need directions on "Text Alignment"

I have used this code to greet user:

<script type="text/javascript">
var d = new Date();
var time = d.getHours();
if (time > 17) 
{
document.write("<b>Good Evening, Thanks For Visiting Us!</b>");
}
else if (time <17 && time >12)
{
document.write("<b>Good Afternoon, Thanks For Visiting Us!</b>");
}
else
{
document.write("<b>Good Morning, Thanks For Visiting Us!</b>");
}
</script>


Its working fine for me, but the problem is

This code writes "Greeting Message" in the left side of the page & i want the Message

To be displayed in the Center(middle) of the page.

What else should i add to the existing code to get it work.

Thanks all.

F4r4Zm0In
Newbie Poster
3 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 
<style type="text/css">
#greeting {
  display: block;
  text-align: center;
}
</style>
<script type="text/javascript">
var d = new Date();
var time = d.getHours();
if (time > 17)
{
document.write("<b id="greeting">Good Evening, Thanks For Visiting Us!</b>");
}
else if (time <17 && time >12)
{
document.write("<b id="greeting">Good Afternoon, Thanks For Visiting Us!</b>");
}
else
{
document.write("<b id="greeting">Good Morning, Thanks For Visiting Us!</b>");
}
</script>


I suspect this will cure your ills

...

langsor
Posting Whiz
390 posts since Aug 2008
Reputation Points: 30
Solved Threads: 36
 

I have made some changes to the code & now its working as expected!

You can have a look at the changes i have made to the code:

<script type="text/javascript">
var d = new Date();
var time = d.getHours();
if (time > 17)
{
document.write("<h5>Good Evening, Thanks For Visiting Us!</h5>");
}
else if (time <17 && time >12)
{
document.write("<h5>Good Afternoon, Thanks For Visiting Us!</h5>");
}
else
{
document.write("<h5>Good Morning, Thanks For Visiting Us!</h5>");
}
</script>
<style type="text/css">
h5 {text-align: center}
h5 {display: block}
</style>
F4r4Zm0In
Newbie Poster
3 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Excellent, I was going to suggest using an element, but was on the fence since the data is the apparent page heading, but not one that would benefit from keywords for SEO or the like and is contextually ambiguous... but good work.

You can, however, skip the h5 {display: block} declaration since elements are already block-level elements and span the entire available space by default.

Ciao

langsor
Posting Whiz
390 posts since Aug 2008
Reputation Points: 30
Solved Threads: 36
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You