Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertically stacked divs have space between them (firefox)

a little css problem that i cannot quite find on SO - although I assume it has been asked before, apologies.

So, here is the html:

<html>
    <body style="color:white">
        <div class="a" style="width: 70%; background: blue;"><p>helloes helloes helloes</p></div>
        <div class="b" style="width: 70%; background: pink;"><p>talk talk talk</p></div>
        <div class="a" style="width: 70%; background: blue;"><p>yay! yay! yay!</p></div>
    </body>
</html>

lovely.

If i open this in ff, i get three vertically stacked divs - but with space in between them! This is not what i wanted! Drama-rama!

ie renders this as i'd expect, which raises some alarm bells.

ie is 9, ff is 11

cheers, andrew!

UPDATE a lot of mentioning the "p" tag - why/how is the p tag affecting anything? Isn't it wrapped by the div, and the div has the background color applied? Shouldn't, in fact, the div just be internally bigger, but with no space between adjacent divs?

UPDATE:

So i tried this html instead:

<html style="margin:0px; padding:0px;">

which didn't fix the issue, and also this:

<body style="color: white; margin:0px; padding:0px;">

which also didn't fix the issue - shouldn't the css be inherited by the "p" tag in both cases? Interestingly, i also examined the resultant css with firebug, and the p tags all have a margin and padding of 0...

ideas?

UPDATE: a lot of responses asking me to set padding to 0. This doesn't work. Any more answers stating that and i'll down vote 'em.

UPDATE: the question is really specific about using inline css. I don't actually care for inline css myself, but why is everybody providing css stylesheets for their answer?

UPDATE: somebody mentioned -webkit, and while i'm not using a google chrome at all, it is an interesting idea. I cannot see any ff related extra css that might be causing this problem, anybody have any ideas?

like image 955
bharal Avatar asked Feb 20 '23 09:02

bharal


1 Answers

I tried it with Chrome and saw the same behavior. After looking at the underlying CSS (F12), Chrome is applying the following two lines to the <p> tag:

-webkit-margin-before: 1em;
-webkit-margin-after: 1em;

If I add the following to the css the blank lines go away:

-webkit-margin-before: 0px;
-webkit-margin-after: 0px;

Hope that helps!

like image 170
JerseyMike Avatar answered Mar 06 '23 02:03

JerseyMike