Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with negative margin value in Firefox

I have an issue with a negative margin in Firefox. My negative margin works in Chrome but doesn't in Firefox.

.search-bar {
    height: 108px;
    position: relative;
    margin-top: -10px;
}
like image 370
Al-Mothafar Avatar asked Jan 31 '14 02:01

Al-Mothafar


People also ask

Are negative margins OK?

It does not break the flow of the page if applied to elements without floats. So if you use a negative margin to nudge an element upwards, all succeeding elements will be nudged as well. It is highly compatible. Negative margins are wholly supported across all modern browsers (and IE6 in most cases).

Is it bad practice to use negative margins CSS?

The downside of negative margins is they are difficult to debug and will make your CSS harder to read. The most often misuses of negative margins that I encounter is when it is used to make up for incorrect layouts elsewhere on the site. This is indeed bad practice.

What is margin negative?

The margin is described as negative or clean when the pathologist finds no cancer cells at the edge of the tissue, suggesting that all of the cancer has been removed.

Why might you use negative margins in your web page?

You give a container a padding so that its contents have some breathing space. However, you want the header to span the entire container, ignoring the padding. Negative margins are the way to go.


2 Answers

The solution simply :

.search-bar {
    height: 98px;
    position: relative;
    top: -10px;
}

I Replaced margin-top with top with the same value, and I decreased height with old margin-top value, and worked like a charm.

like image 174
Al-Mothafar Avatar answered Oct 29 '22 22:10

Al-Mothafar


For everyone still having the same problem, just add float:left to the DOM element with the negative margin. Thanks to @Deepak Yadav for the solution.

like image 44
John Isaiah Carmona Avatar answered Oct 29 '22 22:10

John Isaiah Carmona