Forum Moderators: not2easy

Message Too Old, No Replies

Div positioning

Trying to position text over an image

         

patter

2:47 am on Nov 22, 2007 (gmt 0)

10+ Year Member



I need to place some text over a logo on a site. The site is mostly html but I'm trying to use css to do this so I wouldn't have to edit the image. The logo is 800 pixel's wide and centered. The following code does what I want except that some people say the links added are being displayed off to the left so that if the left edge of the logo is at position 100, the text begins at 50 (just made up numbers). I also notice that using this causes extra space to be inserted at the top of the page, as if a <br> was there.

I'm not at all fluent in css but am trying to learn it. The text I am trying to place over the image is in the <div></div>. Can anyone please point out what I am doing wrong with this code?


<body>
<div>
<div STYLE="position:absolute; top:60px; left: 130px;">
<a href="link1.html">Link1</a>
<a href="link2.html">Link2</a>
<a href="link3.html">Link3</a>
<a href="link4.html">Link4</a>
</div>


<table border="0" cellpadding="0" style="border-collapse: collapse" width="800" align="center">
<tr>
<td>
<table border="0" cellpadding="0" style="border-collapse: collapse" width="100%">
<tr>
<td>
<table border="0" cellpadding="0" style="border-collapse: collapse" width="100%">
<tr>
<td align="center">Title Goes Here</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div>
</body>

Marshall

8:16 am on Nov 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld patter.

It would help to know the doctype you are using and the relevant CSS. Otherwise, the best way to do this (IMHO) is to set the image as a background in the <div> you have the text/links in.

Marshall

adb64

9:42 am on Nov 22, 2007 (gmt 0)

10+ Year Member



I don't understand exactly what you try to establish as I see no IMG tag in the HTML above. But you could use the following code to get the desired effect:

<div style="position: relative;">
<img src="logo.jpg" alt="">
<div style="position: absolute; left: 100px; top: 20px;">
Text to place over the logo
</div>
</div>

patter

1:57 pm on Nov 23, 2007 (gmt 0)

10+ Year Member



Thank you for the replies. The doc type is HTML 4.01 Transitional//EN and this is part of a php site, if that makes a difference. The posted code seems to work but I haven't been able to get anyone to test it due to the holiday so I can't say for sure. I did notice that when the logo is clicked on, it "jumps" a little. What I mean by that is that if I click on the image, everything below the image moves up on the page a little but moves back down once released. Is that a side effect of using this method?

patter

2:29 pm on Nov 23, 2007 (gmt 0)

10+ Year Member



I just noticed that the "jumping" I mentioned is only in FireFox. It is steady in IE 7.

Xapti

5:33 pm on Nov 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Truthfully speaking, it's somewhat frustrating to help coders with your level of knowledge. You should be learning lots more about HTML, CSS, and proper website design.

For starters, you say that your div is centered, but I do not see how that is possible, based on the current code given. Left:130 offsets it 130pixels to the right, but that does not center it if either the text size is increased, or if the window size is increased.

Another thing is you say your site is HTML 4.01 transitional, but you should really copy and paste what you wrote, because the reason for asking doctype is not only to know what doctype you are trying to go for, but also to know if you posted a FULL doctype which includes the link to the DTD (and also as a minor thing, if there's any typos).

As people have pointed out already, you want text over an image, but you don't tell us anything about this so-called image. Where it is, or if it's a background image or not. Using a background image for the div would probably be the best idea to get what you want.

CSS and HTML go hand in hand. You cannot have applicable CSS without HTML, and without using depreciated and/or non-semantic code, [styled] HTML (which accounts for virtually all HTML) cannot be done without CSS. As such, you should include all the relevantCSS code you used, as well as the relevant HTML. I noticed the inline CSS you included on the page (for the absolute positioning), but was that it? If so, then you also probably didn't include enough relevant HTML because there is no IMG tag around.

When it comes to testing a page while designing, the best thing to do would be to design based on a compliant browser like Opera or Firefox first (although since Firefox is more widely used, that may be the better choice if you only choose one), and THEN add fixes for Internet Explorer's quirky rendering bugs. Also note that IE6 and IE7 have some DIFFERENT rendering bugs, which can be annoying.