Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: CSS - Image behind Text
PostPosted: August 8th, 2009, 11:22 pm 
Rsbandb Donor
User avatar
Offline

Joined: February 4th, 2006, 5:40 pm
Posts: 1832
Location: 127.0.0.1
RS Status: P2P
I am trying to make a piece of text that has an image behind it.

I can set the background-image property to the image I want, however, it cuts off where the text ends.

How can I make the image stay full size, with the text in the center?

Thanks.

_________________
Image
Mike wrote:
Say NOOOOOOOOOOOOOOOOOOOO to star trek


Top
 Profile  
 
 Post subject: Register and login to get these in-post ads to disappear
PostPosted: August 8th, 2009, 11:22 pm 
Rsbandb Donor

Joined: September 9th, 2004, 1:47am
Posts: 9047
Location: In your web browserz


Top
  
 
 Post subject: Re: CSS - Image behind Text
PostPosted: August 9th, 2009, 4:34 am 
Rsbandb Donor
Offline

Joined: October 25th, 2004, 10:12 pm
Posts: 3055
Location: New Zealand nz
RS Name: Chief. Snake
RS Status: Retired
Clan Name: Bits and Bytes
You will need something like this:

<style type="text/css">
#text-wrapper {
    background: url('./yourimage.png') no-repeat;
    display: table;
    height: height of the background image;
    text-align: center;
    width: width of the background image;
}

    #text-wrapper span {
      display: table-cell;
      vertical-align: middle;
    }
</style>

<div id="text-wrapper">
    <span>This is where your text goes</span>
</div>



However as I would personally recommend avoiding the display: table; vertical alignment hack (you'd need to add some absolute positioning in IE only, to get it to work in IE), you should use padding instead, so you'll want some CSS more like this:

<style type="text/css">
#text-wrapper {
    background: url('./yourimage.png') no-repeat;
    height: height of the background image;
    text-align: center;
    width: width of the background image;
}

    #text-wrapper span {
      display: block;
      padding: as necessary until the height+width of the background is filled;
    }
</style>

_________________


Top
 Profile  
 
 Post subject: Re: CSS - Image behind Text
PostPosted: August 9th, 2009, 10:37 am 
Rsbandb Donor
User avatar
Offline

Joined: August 18th, 2008, 12:19 pm
Posts: 357
Location: England england
RS Name: VettelS
RS Status: P2P
<div style="background:url(image url) no-repeat; height: height of image; width: width of image; text-align:center;">

<p>text here</p>

</div>

_________________
My blog


Top
 Profile  
 
 Post subject: Re: CSS - Image behind Text
PostPosted: August 9th, 2009, 2:23 pm 
Rsbandb Donor
User avatar
Offline

Joined: February 4th, 2006, 5:40 pm
Posts: 1832
Location: 127.0.0.1
RS Status: P2P
Thanks to both of you :)

This can now be locked.

_________________
Image
Mike wrote:
Say NOOOOOOOOOOOOOOOOOOOO to star trek


Top
 Profile  
 
Display posts from previous:  Sort by  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to: