Author Topic: CSS resizable background image for a button  (Read 1628 times)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,133
  • Reputation: +26/-1
    • View Profile
CSS resizable background image for a button
« on: March 09, 2010, 12:44:42 PM »
I have a button (background image) for both link and submit elements. The image has all 4 edges drawn. How can I make it resizable?

Offline Marek

  • Level 17
  • *
  • Posts: 170
  • Reputation: +6/-0
  • XHTML, CSS, JS, PHP and MySQL are my pantheon.
    • View Profile
Re: CSS resizable background image for a button
« Reply #1 on: March 09, 2010, 04:40:28 PM »
If you want it width-resizable, then you can split the background into two parts and use the Sliding Doors technique.

However this requires adding markup to your elements, because you're essentially layering two backgrounds. CSS3 allows multuple backgrounds per element, but that's still out of reach.

If you want the elements to be both width- and height-resizable, then it's going to involve more CSS wizardry and a lot more markup. For instance, to achieve rounded corners, there's about a dozen of different methods, and each one uses complex tangles of CSS and tons of extra HTML markup. And that's just for the corners: if you want to make an entire frame out of images, then it's even messier. Here, too, CSS3 will eventually save the day, with support for border images as well as built-in rounded corners.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,133
  • Reputation: +26/-1
    • View Profile
Re: CSS resizable background image for a button
« Reply #2 on: March 09, 2010, 06:36:27 PM »
I need only width resize, height is fixed.

Just plain ugly resize (stretch), no extravagances. I think it must be doable via one CSS tag, but do not know how such tag is called :D Something like "repeat-x" but not repeat the image but stretch it like "stretch-x"...

Offline Marek

  • Level 17
  • *
  • Posts: 170
  • Reputation: +6/-0
  • XHTML, CSS, JS, PHP and MySQL are my pantheon.
    • View Profile
Re: CSS resizable background image for a button
« Reply #3 on: March 09, 2010, 10:35:52 PM »
There is no such way to stretch the background image in CSS, unfortunately.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,133
  • Reputation: +26/-1
    • View Profile
Re: CSS resizable background image for a button
« Reply #4 on: March 10, 2010, 03:49:32 AM »
What!? That's terrible!

So, how can I do something like that (any technique):
- a box with stretched image
- a text on top of it
- the box width depends on the text size (autostretch)
- height is fixed

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: CSS resizable background image for a button
« Reply #5 on: March 10, 2010, 05:39:34 AM »

Offline dsheroh

  • Level 21
  • *
  • Posts: 235
  • Reputation: +6/-0
  • Perl Vicar
    • View Profile
    • Psi Rangers
Re: CSS resizable background image for a button
« Reply #6 on: March 10, 2010, 06:22:12 AM »
There is no such way to stretch the background image in CSS, unfortunately.

CSS3 adds a background-size property, as shown at http://webdesign.about.com/od/css3/f/blfaqbgsize.htm  There are also some examples on that page of how to fake it in CSS2.

http://www.htmlite.com/faq022.php demonstrates an alternate approach.  ("The trick to stretching an image in the background is to not have the image in the background. Instead, it is placed on the webpage (like any other image) and everything else is layered on top of it using css.")

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,133
  • Reputation: +26/-1
    • View Profile
Re: CSS resizable background image for a button
« Reply #7 on: March 10, 2010, 09:00:34 AM »
So, the simpliest solution would be cutting the image into two and using Sliding Doors technique?

Should I expect any problems with IE6?

Offline Hawkins

  • Level 7
  • *
  • Posts: 35
  • Reputation: +0/-0
    • View Profile
    • Indie Resource
Re: CSS resizable background image for a button
« Reply #8 on: March 10, 2010, 11:19:55 PM »
I would have no Idea because I am a firefox user but just give it a try

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal