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.

Member Avatar for langsor
<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

...

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>
Member Avatar for langsor

Excellent, I was going to suggest using an <h> 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 <h> elements are already block-level elements and span the entire available space by default.

Ciao

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.