tags:

views:

140

answers:

2

I was having trouble with two types of buttons. It was a form button and a css button basically. And I was advised that the css button whould use display:inline-block; This made the whole a href tag actually look like a button. But this invisible margin seems to be screwing up something. I tried separating them into separate css classes, but oddly, applying a real margin to the css button gives an additional margin as well. What's causing this?

You can easily see it here (low graphics): www.matkalenderen.no

Basically, code looks like this:

      <input type="submit" value="Logg inn" class="button_blue" alt="ready to login"> 
      <a class="button_css_red" href="access.php">Glemt passord</a> 

CSS

.button_red, .button_blue, .button_css_red, .button_css_blue {
    background-image:url("../img/sprite_buttons.png");
    background-repeat:no-repeat;
    border: none;
    color:#FFFFFF;
    display:inline-block;
    display:inline-block;
    font-size:12px;
    height:27px;
    width:98px;
}

.button_css_red, .button_css_blue {
    margin-top:20px;
}
A: 

Try resetting your margins;

.button_red, .button_blue, .button_css_red, .button_css_blue 
{
margin: 0;
}

And you have display:block; in there twice. Also make sure that the button width/height isn't wider than that image itself, I had that problem yesterday :).

And also try a negative margin on;

.button_css_red {
    margin-top:-10px;
}​

I use that sometimes with things like this.

After looking at it with Firebug, I would suggest you could wrap the two elements in two relatively positioned divs and move them to where you desire. I've used this technique on the site I've been working on and it works great :)

Kyle Sevenoaks
Just tried this, did nothing actually. Also, the negative margin also affects the other button as well. Even though the code does not cross, or should not do it. It AFFECTS the other button, but the margin isn't applied to it. You can see it better with FireBug on the actual site.
Kenny Bones
Yeah, I saw. I meant for you to make a new class `.button_css_red` on it's own and applying the negative margin to only the red button. Did you try wrapping them individually with different divs? Jeg vil se på siden nå.
Kyle Sevenoaks
-1: you have Firebug but won't even use it to check if your suggestion works?
ANeves
If you read the answer, it says that yes I did check it, and suggested that he use another method.
Kyle Sevenoaks
The red button has it's own class and the negative margin was applied to that only. And it didn't solve the problem. The negative margin is applied, but the other button is affected as well. Meaning, the css isn't applied to it, but it's like an invisible effect is affecting it.
Kenny Bones
This is indeed a strange problem, I just took another look in Firebug, you have .button_css_red, .button_css_blue {margin-top:-10px;}. when I meant for you to make `.button_css_red {margin-top:-10px;`} Without the blue, so .button_blue has different styles away from the red button :)
Kyle Sevenoaks
@Kyle Sevenoaks, I find your answer is not useful, which is the definition of a downvote. You don't present anything valuable. The only thing you propose is moving the `a` button with `position: relative; top: -[Y]px;` (which may sort of work but is not right, imo - but that's irrelevant) - and even then you sugest wrapping in divs, for whatever reason. Do you feel I am wrong in downvoting? How do you feel your answer is not "not useful"?
ANeves
I feel that it'swrong in downvoting because I had come across this problems before, and used both of those methods to fix it, they both work and I don't feel there is anything wrong with it. His solution used line height, I wouldn't have done it that way, but looks like there are a few solutions to each problem. I have made nonsensical answers before and removed them, this I consider to be some helpful, but if it's really that bad I'll remove it.
Kyle Sevenoaks
A: 

Just found the answer myself :)

Looks like I was able to fix it by applying a line-height of about 31 pixels.

Kenny Bones
Good job, liked the site by the way.
Kyle Sevenoaks
Nice job, if your question has been resolved please tick the answer box so that it stops showing up as unanswered. Thanks.
David
Yes that would be nice if it was not still showing up as unanswered.
John