views:

742

answers:

5

Anyone know if there's a bullet-proof (standards-compliant to XHTML1.1 strict, cross-browser, non-javascript) way to use CSS and background images to turn an inline link into a visual button that will stretch to accommodate different amounts of text (or text resizing)?

I'm thinking I need to use background images as the designer's buttons have rounded corners with a different coloured border. It must work in IE6 (Government job).

Im pretty sure the answer is no, but as always thought it worth a check.

Amongst other things, I've already tried variations on the sliding doors technique, but can't make it work as the solution needs to work inline (i.e. within a paragraph) and I can't set a fixed width.

EDIT: There are several buttons, each of which has a different colour for foreground, border and background. They also have a gradient 'face', but no need for transparency or anything else 'unorthodox'. Unfortunately I can't link to examples as I'm under an NDA.

A: 

Yeah, you probably need to make image buttons for this.

Anthony Mills
Thanks but that won't work as a form within a paragraph won't validate.
da5id
...plus the method you've linked to uses Javascript.
da5id
It only needs JavaScript if you're trying to attach event handlers or funky hover effects. Can you put the form surrounding the paragraph?
Anthony Mills
But it's fixed size. I need the button to be able to stretch.
da5id
You can use the image to repeat-xthen set the <a> to have a min-height of X amount of pixels. It will expand with the letter size and not get smaller then your specified width.
Phil
I can't just set the image to repeat 'cos of the rounded corners - that's why I went down the 'sliding doors' path in the first place.
da5id
+1  A: 

I'm not sure if this will fit your needs, but I helped someone with hoverable rounded buttons in this post... it uses only HTML and CSS.

fudgey
It doesn't directly, but I followed a link from your post to find my answer so +1 Cheers :)
da5id
Hehe, so you found the links I posted there as well ;) Glad you got your answer :P
fudgey
+1  A: 

I don't think you can do this within your restrictions. The problem is that you have one element, but to properly do stretching, you need three (unstretched left side, stretched center, unstretched right side).

John Fisher
Good advice (cheers), but I've managed to do it with a single span within an anchor. I'm going to answer my own question in case anyone else needs to do it.
da5id
Ah. So you did it with two elements instead of one.
John Fisher
+2  A: 

I've ended up fixing it by using a variation of the sliding doors technique documented very nicely here. Basically, the difference between it and what I had been doing was this version uses the CSS property "display: inline-block".

da5id
...and thanks everyone for all the help :)
da5id
A: 

Just as an aside in future, here's a page on CSS button styling.

Anthony Mills