0

I have an image with rounded corners(png transparent on the corners), about 150px wide, and 25px height, so i'm trying to use it, but it doesn't work for me:

<button><span>Click me</span></button>

And the css:

button{
    border:0;
    background:url(../images/button.png) no-repeat top left;
    height:24px;
    padding-left:10px;
}

And

button span{
    display:block;
    background:transparent url(../images/button.png) no-repeat top right;
    height:24px;
    padding-right:10px;
}

But it doesn't work correctly, the right corner isn't displayed correctly.Any help?

Best Regards,

1
  • Why not have just one image as the background of the button? Commented Jul 9, 2009 at 17:44

3 Answers 3

1

Using Firebug (use it!) it is clear what is happening. Your right corner shows, but as the the button underneath it continues, you simply don´t see it.

You can solve that using two images, a small one (not so wide, minimum width the padding on the left side) for the left corner and a very wide one for the right corner. That way your buttons don´t overlap and you get the desired effect.

Sign up to request clarification or add additional context in comments.

1 Comment

the first four words here are enough for me to vote this one up :)
0

First things first: How is it displayed? You're using the same background images for both left and right corner. Is that in order? (I realize that technically it could be) Also, you might want to try and switch the two (left/right), as span is not a block element, and that might be causing your problems (much in the same way that you can't, say, set a width to a span, unless you also set it to render as a block)

Comments

0

your span and button elements have the same height (which is smaller than image height by the way). Another observation: why do you need span element at all?

start with the simplest way to do something:

    <button>Click me!</button>

button {
border: 1px solid #ff0;
padding: 10px;
display:block;
background:transparent url(../images/button.png) no-repeat top centre;
height:25px;

}

this should display your image. Use border property to debug CSS

6 Comments

i don't get your example. there's no image in your css at all...? anyway, you notice how one background is fixed in the right corner, and another in the left? you can't set one left-background and one right-background to the same element, so you'd need to wrap one in another.
my previous comment was for gnomixa. @uffo, regarding your example, since that background image is wider than the element, you won't see all of it. to use an image like that, you'll need to have a fixed width on your button that matches that of your background image, and if you're doing it like this, then indeed, you're just as well off without the span.
just read the end of your comment now. Height might be the culprit then. Why is he setting it to 24px while the image is 25px long?
I want to use this tehnic, because in this way, i can have large buttons with a lot of text, or just a lil bit a text, i want to be fluid
@gnomixa: just to prove a point, tho, using the same image twice could totally make sense if you're doing it right: davidhedlund.se/tmp/button.htm
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.