tags:

views:

357

answers:

2

I have a 1px wide by 35px high image, that I set as background for my h2 elements. The accompanying CSS is as follows:

h2 {
    background:transparent url(./images/h1_bg.gif) repeat-x left top;
    font-size:18px;
}

As a result, the background is set as the image no matter what the length of the heading is, as long as the heading fits in one line. If the heading spills over to next line, then image is not set as background for the wider area, as it repeats only in x direction. I think I need to create another image, example 1px wide by 60px high image and set it as background of the two-line heading. But I need some way to check if the heading is a two-line heading or not, so I can change the image background. How do I do that? Plus, is there some other way to accomplish this task?

+3  A: 

You usually deal with this by just creating a very tall image, like 100 pixels or more. Hold the bottom row colour for the remainder of the height.

U62
Or, if the bottom of the image is a solid colour all the way across, you can set a background colour to match and leave the image as-is
ScottE
True. ALthough if you have trasparent rounds or other cutouts you can't use background-color.
U62
U62 -"What do you mean by "Hold the bottom row color for the remainder of the height?"
Steve
I mean if you have for example a 30px tall image with a gradient from top to bottom, load it up into your favourite image editing app, extend the height to 100px (or whatever) and then colour the new pixels in the same colour as the bottom row of the original image. An easy way to do this in most apps is to rectangle select the bottom row of pixles, copy and then paste and then stretch the bottom of the selection to the bottom of the image.
U62
Ah, I see. I thought it had something to do with css/html. Thanks.
Steve
+2  A: 

You can do this by using height.

  if($j("h1").height() > 30)
 {
  $j("h1").css("background","transparent url(./images/h1_bg_0.gif) repeat-x left top")
 }
  else
 {
  $j("h1").css("background","transparent url(./images/h1_bg_1.gif) repeat-x left top")
 }
Srikanth
You actually want to depend on javascript for something than can easilly be solved with static markup/css?!
U62