Floating Text Above an Image

Posted on 2007-11-30
Last Modified: 2010-05-04
Hello Experts,

I have a layout in which I've used two jpeg images to form "visual containers" for my site's layout.  I would like to layer textual content over these images.  

Both jpeg images are equal to the width of my website layout.  The entire layout in centered.  As the browser is resized, the page layout remains centered in the window.  

I would like to layer textual content over these images, and I would like for the textual content to remain in its place (relative to the photo it is layered over) as the browser window is readjusted.  

I've tried to accomplish this with CSS, but am unable to force the text over the pictures.  The text simply sits at the bottom edge of the last picture, instead of hovering over the image, as a layer.  Also, the text will not stay in its place when the browser windows is readjusted.  

Is there an expert out there who knows how to make this work?  I'm not sure of what I'm doing wrong here...   :0(
    position: relative;
    left: 405;
    top: 20;
    float: left;
    margin-left: auto;
    margin-right: auto
<div id="topmenuunderliner"><img src="top_menu_underliner.jpg">
<div id="wrapper">
    <img src="leftmainpic_palette.jpg" />
    <img src="small_image_palette_triple_v2.jpg" style="margin-left: 21px" />
    <img src="rightsidebarpalette_v2.jpg" style="margin-left: 166px" />
<div id="wrapper2">
    <img src="three_section_palette_thin_lines_vs2.jpg"> 
<div id="bottomadvertbanner">
    <img src="bottom_advert_banner.jpg"> 
<div id="bottommiddlesegment">
<div id="musthavestitle">
    This is text...</div>
<div id="musthavestext">
    This is text, too...</div>
<div id="musthavessubtitle">
    This is text here, as well...</div>

Open in new window

Question by:TrickyFingers
  • 2
LVL 28

Assisted Solution

gamebits earned 250 total points
ID: 20380844
2 options:

1) set your image as background image.
2) use Z index o position image and text.

Accepted Solution

gxp071 earned 250 total points
ID: 20381031
Hi ,

if im  understanding your post correctly what your tiring to do would be traditionally done using div backgrounds.  What you probably need to read up on is a technique called sliding doors which lets you use three images and 3 containers to make a variable width image container.  I have attached a simple example to try and get across the idea.

Any content images or text in the header div or content div will now be on top of you backgrounds.  the effect can be used again and again, all you need is three more divs or other elements.

Let me know if this is any help at all, if not can you post a link to a live version of the page it makes it alot easer to debug the code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<style type="text/css" media="screen">
			margin: 0px;
			/*background repeat img of sliding doors background */
			background:#f50 url(middle-bg.gif) repeat-y;
			margin: 0 auto 0 auto;
		#pagewrapper #inside{
			/*top image of sliding doors background */
			background:url(top-bg.gif) no-repeat top;
		/*bottom/closing img of the sliding door background */
			background:url(bottom-bg.gif) no-repeat bottom;
	<div id="pagewrapper">
		<div id="inside">
			<div id="header">
				some text
			<div id="content">
				blar blar blar blar this is text

Open in new window

LVL 12

Expert Comment

ID: 20381529
Hello TrickyFingers,

Here is a general layout that will allow you to layer text over images...

I hope this helps!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#wrapper {
	width: 60%;
	margin: 0 auto;
	position: relative;
#text-layer {
	position: absolute;
	top: 0;
<div id="wrapper">
  <div id="bg-layer"><img src="img.jpg" /> </div>
  <div id="text-layer">Text</div>

Open in new window

LVL 12

Expert Comment

ID: 20381580
Hi TrickyFingers,

Depending on your layout, you may be able to try...

#bottommiddlesegment {
position: relative;
top: -100px; /* move up 100px - change to fit layout */

As gxp071 said, it is easier to make suggestions when a complete page is available to review.

I hope this helps!


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change button location when you go on your cellular device 21 32
CSS: Making responsive table look nicer 7 31
Are these icons a web font? 3 21
GET error with Font Awesome 3 18
This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question