?
Solved

text backround image

Posted on 2011-05-11
9
Medium Priority
?
260 Views
Last Modified: 2012-05-11
Hello experts.
I want to use a backround image for my titles.
The width must depend the text.
I have a main image that has a big width and a right image that is "closing" the backround.
I post an image how it looks like and the two parts of the images.
Any help with this?
(it is a test image,so don't care about the widths and heights)
test.gif
0
Comment
Question by:Panos
  • 5
  • 4
9 Comments
 
LVL 10

Expert Comment

by:gavsmith
ID: 35736763
Setup a style similar to this (I've used H1 but you could change that to a class if you like):

H1
{
    background-image: url('../images/main_part.png');
    background-repeat: no-repeat;
    background-position: left;
    padding-left: 10px;
    display:inline-block;
}

H1 span
{
    padding-right:10px;
    background-image: url('../images/right_part.png');
    background-repeat: no-repeat;
    background-position: right;
}

Open in new window


you may need to play with the padding to get the correct sizes for your picture.

Then create a title like this:

        <h1><span>Test</span></h1>

Open in new window


regards
0
 
LVL 2

Author Comment

by:Panos
ID: 35736903
Hi gavsmith
Thanks for the fast post.
Take a look at my code.I have a div instead of h1 and set a heigth for div and span but is still looks bad.
i test this with my original images
<style type="text/css">
.main
{
    background-image: url('style/images/titlepapyrus_left.gif');
    background-repeat: no-repeat;
    background-position: left;
    padding-left: 10px;
	padding-bottom: 0px;
	margin:0;
    display:inline-block;
	height:46px;
}

.main span
{
    padding-right:20px;
    background-image: url('style/images/titlepapyrus_right.gif');
    background-repeat: no-repeat;
    background-position: right;
	height:46px;
	color:#FFF;
}
</style>

 <div class="main"><span>Testtestetststst</span></div>

Open in new window

test2.gif
0
 
LVL 10

Expert Comment

by:gavsmith
ID: 35737168
Try adding display:inline-block to the span element also:

<style type="text/css">
.main
{
    background-image: url('style/images/titlepapyrus_left.gif');
    background-repeat: no-repeat;
    background-position: left;
    padding-left: 10px;
	padding-bottom: 0px;
	margin:0;
    display:inline-block;
	height:46px;
}

.main span
{
    padding-right:20px;
    background-image: url('style/images/titlepapyrus_right.gif');
    background-repeat: no-repeat;
    background-position: right;
	height:46px;
	color:#FFF;
    display:inline-block;
}
</style>

 <div class="main"><span>Testtestetststst</span></div>

Open in new window


regards
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Panos
ID: 35737252
Yes.It is much better now.
Do i have to add an extra tag to enclose the text to add padding to center ......aso?
0
 
LVL 10

Expert Comment

by:gavsmith
ID: 35737641
Yes I believe you will have to. If you apply it to the span it will make the image go out of line.
0
 
LVL 2

Author Comment

by:Panos
ID: 35737693
The following code is working.
Is there any hack for IE?
<style type="text/css">
.main
{
    background-image: url('style/images/titlepapyrus_left.gif');
    background-repeat: no-repeat;
    background-position: left;
    padding-left: 20px;
	padding-bottom: 0px;
	margin:0;
    display:inline-block;
	height:46px;
}

.content
{
    padding-right:20px;
    background-image: url('style/images/titlepapyrus_right.gif');
    background-repeat: no-repeat;
    background-position: right;
	height:46px;
}
.content span{
	 color:#FFF;display:inline-block; padding-top:10px; font-size:18px; font-weight:bold;
}
</style>

 <div class="main"><div class="content"><span>Testtestetststst</span></div></div>

Open in new window

0
 
LVL 10

Accepted Solution

by:
gavsmith earned 2000 total points
ID: 35738534
You could try:

<style type="text/css">
.main
{
    background-image: url('style/images/titlepapyrus_left.gif');
    background-repeat: no-repeat;
    background-position: left;
    padding-left: 20px;
	padding-bottom: 0px;
	margin:0;
    display:inline-block;
	height:46px;
    zoom:1;
    *display:inline;
}

.content
{
    padding-right:20px;
    background-image: url('style/images/titlepapyrus_right.gif');
    background-repeat: no-repeat;
    background-position: right;
	height:46px;
    zoom:1;
    *display:inline;
}
.content span{
	 color:#FFF;display:inline-block; padding-top:10px; font-size:18px; font-weight:bold;zoom:1;
}
</style>

 <div class="main"><div class="content"><span>Testtestetststst</span></div></div>

Open in new window

0
 
LVL 2

Author Comment

by:Panos
ID: 35738684
Perfect!!
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 35738688
Thank you for your help!
regards
panos
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 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