473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Centering an image with text

I want to center an image on the screen and have text centered over the
image. What's the best way to do this?

I've been playing with style tags and I can get the stuff to center
automatically OR have the text appear on top of the image. But in the
second case, the image and text aren't centered properly.

Any help is appreciated...

Jerry
Nov 19 '05 #1
6 2294
Jerry,

How about adding the text as part of the image on the fly. Check this out:

http://www.vb-helper.com/howto_net_watermark.html

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:OF*************@TK2MSFTNGP12.phx.gbl...
I want to center an image on the screen and have text centered over the
image. What's the best way to do this?

I've been playing with style tags and I can get the stuff to center
automatically OR have the text appear on top of the image. But in the
second case, the image and text aren't centered properly.

Any help is appreciated...

Jerry

Nov 19 '05 #2
Interesting, but not practical for my purpose..

Seems it should be something pretty easy to do. Right now I am using an ASP
panel with a background image. I can cente rthe text horizontally on the
image, but not vertically. Any idea how to center vertically?
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Jerry,

How about adding the text as part of the image on the fly. Check this out:

http://www.vb-helper.com/howto_net_watermark.html

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:OF*************@TK2MSFTNGP12.phx.gbl...
I want to center an image on the screen and have text centered over the
image. What's the best way to do this?

I've been playing with style tags and I can get the stuff to center
automatically OR have the text appear on top of the image. But in the
second case, the image and text aren't centered properly.

Any help is appreciated...

Jerry


Nov 19 '05 #3
All of the examples I've found place the image as a background image like
you've done, but they are using a div tag instead of panel. That shouldn't
matter I think.

Then they use a separate div for the text and place it with another class.
The final code is like this:

div#test {
background-image: url(/images/backgroundimage.JPG);
background-repeat: no-repeat;
height: 500px;
width: 380px;
}

<div id="test">Superimposed Text</div>

If the text positioning relative to the image is simple, you could add any
necessary text formatting to the div#test style and use the padding-top and
padding-left attributes to position the text in the <div>. On the other
hand, if you need more control over text positioning, or the text consists
of multiple lines and paragraphs, you can nest the text within another
<div>, like this:
div#testtext {
position: relative;
height: auto;
width: auto;
left: 25px;
top: 200px;
}

<div id="test"><div id="testtext">Superimposed Text</div></div>


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Interesting, but not practical for my purpose..

Seems it should be something pretty easy to do. Right now I am using an
ASP
panel with a background image. I can cente rthe text horizontally on the
image, but not vertically. Any idea how to center vertically?
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Jerry,

How about adding the text as part of the image on the fly. Check this
out:

http://www.vb-helper.com/howto_net_watermark.html

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:OF*************@TK2MSFTNGP12.phx.gbl...
>I want to center an image on the screen and have text centered over the
> image. What's the best way to do this?
>
> I've been playing with style tags and I can get the stuff to center
> automatically OR have the text appear on top of the image. But in the
> second case, the image and text aren't centered properly.
>
> Any help is appreciated...
>
> Jerry
>
>



Nov 19 '05 #4
The padding is the key... Not really a solution for true vertical
centering, but the text is static so the padding works in this case. Thanks
for your insight.

Jerry
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
All of the examples I've found place the image as a background image like
you've done, but they are using a div tag instead of panel. That shouldn't
matter I think.

Then they use a separate div for the text and place it with another class.
The final code is like this:

div#test {
background-image: url(/images/backgroundimage.JPG);
background-repeat: no-repeat;
height: 500px;
width: 380px;
}

<div id="test">Superimposed Text</div>

If the text positioning relative to the image is simple, you could add any
necessary text formatting to the div#test style and use the padding-top and padding-left attributes to position the text in the <div>. On the other
hand, if you need more control over text positioning, or the text consists
of multiple lines and paragraphs, you can nest the text within another
<div>, like this:
div#testtext {
position: relative;
height: auto;
width: auto;
left: 25px;
top: 200px;
}

<div id="test"><div id="testtext">Superimposed Text</div></div>


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Interesting, but not practical for my purpose..

Seems it should be something pretty easy to do. Right now I am using an
ASP
panel with a background image. I can cente rthe text horizontally on the image, but not vertically. Any idea how to center vertically?
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Jerry,

How about adding the text as part of the image on the fly. Check this
out:

http://www.vb-helper.com/howto_net_watermark.html

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:OF*************@TK2MSFTNGP12.phx.gbl...
>I want to center an image on the screen and have text centered over the > image. What's the best way to do this?
>
> I've been playing with style tags and I can get the stuff to center
> automatically OR have the text appear on top of the image. But in the > second case, the image and text aren't centered properly.
>
> Any help is appreciated...
>
> Jerry
>
>



Nov 19 '05 #5
Jerry,

You're welcome. Happy coding!

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:ON**************@TK2MSFTNGP14.phx.gbl...
The padding is the key... Not really a solution for true vertical
centering, but the text is static so the padding works in this case.
Thanks
for your insight.

Jerry
"S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
All of the examples I've found place the image as a background image like
you've done, but they are using a div tag instead of panel. That
shouldn't
matter I think.

Then they use a separate div for the text and place it with another
class.
The final code is like this:

div#test {
background-image: url(/images/backgroundimage.JPG);
background-repeat: no-repeat;
height: 500px;
width: 380px;
}

<div id="test">Superimposed Text</div>

If the text positioning relative to the image is simple, you could add
any
necessary text formatting to the div#test style and use the padding-top

and
padding-left attributes to position the text in the <div>. On the other
hand, if you need more control over text positioning, or the text
consists
of multiple lines and paragraphs, you can nest the text within another
<div>, like this:
div#testtext {
position: relative;
height: auto;
width: auto;
left: 25px;
top: 200px;
}

<div id="test"><div id="testtext">Superimposed Text</div></div>


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Jerry Camel" <rl*****@msn.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> Interesting, but not practical for my purpose..
>
> Seems it should be something pretty easy to do. Right now I am using
> an
> ASP
> panel with a background image. I can cente rthe text horizontally on the > image, but not vertically. Any idea how to center vertically?
>
>
> "S. Justin Gengo" <sjgengo@[no_spam_please]aboutfortunate.com> wrote in
> message news:%2****************@TK2MSFTNGP09.phx.gbl...
>> Jerry,
>>
>> How about adding the text as part of the image on the fly. Check this
>> out:
>>
>> http://www.vb-helper.com/howto_net_watermark.html
>>
>> --
>> Sincerely,
>>
>> S. Justin Gengo, MCP
>> Web Developer / Programmer
>>
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzsche
>> "Jerry Camel" <rl*****@msn.com> wrote in message
>> news:OF*************@TK2MSFTNGP12.phx.gbl...
>> >I want to center an image on the screen and have text centered over the >> > image. What's the best way to do this?
>> >
>> > I've been playing with style tags and I can get the stuff to center
>> > automatically OR have the text appear on top of the image. But in the >> > second case, the image and text aren't centered properly.
>> >
>> > Any help is appreciated...
>> >
>> > Jerry
>> >
>> >
>>
>>
>
>



Nov 19 '05 #6
the code below should work

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Jerry Camel" <rl*****@msn.com> wrote in message
news:OF*************@TK2MSFTNGP12.phx.gbl...
I want to center an image on the screen and have text centered over the
image. What's the best way to do this?

I've been playing with style tags and I can get the stuff to center
automatically OR have the text appear on top of the image. But in the
second case, the image and text aren't centered properly.

Any help is appreciated...

Jerry

<%@ Page Language="C#" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Dead Centre Controls Example</title>
<style type="text/css" media="screen"><!--
body
{
color: white;
background-color: white;
margin: 0px
}

#horizon
{
color: white;
background-color: transparent;
text-align: center;
position: absolute;
top: 50%;
left: 0px;
width: 100%;
height: 1px;
overflow: visible;
visibility: visible;
display: block
}

#content
{
font-family: Verdana, Geneva, Arial, sans-serif;
background-color: transparent;
margin-left: -125px;
position: absolute;
top: -35px;
left: 50%;
width: 250px;
height: 70px;
visibility: visible
}

..bodytext
{
font-size: 14px
}

..headline
{
font-weight: bold;
font-size: 24px
}

#footer
{
font-size: 11px;
font-family: Verdana, Geneva, Arial, sans-serif;
text-align: center;
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
height: 20px;
visibility: visible;
display: block
}

a:link, a:visited
{
color: #06f;
text-decoration: none
}

a:hover
{
color: red;
text-decoration: none
}

--></style>
</head>

<body>
<div id="horizon">
<div id="content">
<div class="bodytext">

<body>

<form runat="server">
<asp:Panel id="Panel1" runat="server"
style="padding:15,15,15,15;
background-color:red;
border-color:black;border-width:1;
border-style:solid">

<asp:Label id="Label1"
Text="Some Centered Controls"
Font-Name="verdana"
Font-Size="12"
runat="server"/>

</asp:Panel>
</form>
</div>
</div>
</div>

</body>

</html>
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Greg Shannan | last post by:
I normally centre an image using a <p align="center"> ... </p> format, but I understand that this is "deprecated" in the latest standard in favour of styles. The problem is that I cannot find a...
19
by: George Ziniewicz | last post by:
.. I try to use CSS when possible, though I am still learning and don't maximize its use. In particular, I still use a table to provide for a centered image in a few slideshows (though table...
18
by: Heath | last post by:
Is it proper to center images in a <div> by using the text-align: center property? Or is there a better way?
2
by: Ryan W Sims | last post by:
I'm having trouble with centering in IE... http://www.ryanwsims.com/koh/ The image should center over the text. It does in Firebird, but not in IE for some reason. If you look at ...
3
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a...
2
by: tonsi | last post by:
I have a page but it wont center the div. Can anyone take a look at it and help. When I try to center in the body using text-align: center; it doesn't work with the main container (called Table_01)....
9
by: CJM | last post by:
I've inserted a new banner in an existing page and I want the banner image to be centered (horizontally) within its container. I'm not bothered whether the accompanying line of text is restricted...
1
by: =?Utf-8?B?ZnJhbmt5?= | last post by:
Hello, I've created a table that has two rows that are span across three columns. The third row has three columns, each with an image. The last row is also span accross three columns. The span...
4
by: harryusa | last post by:
I am trying to center 2 images concentrically which are z-indexed to lay on top of each other making an image with a border from another image that has a transparent center. I need the images to be...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.