Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS multi-column layout leaves unwanted top and bottom margin

I'm experimenting with CSS3 columns, and I noticed there are top and bottom margins added, despite that I explicitly set them to 0. Here's a screenshot:

enter image description here

I've highlighted the margins in yellow. The red rectangles are block level element outlines drawn from the Web Developer Toolbar add-on in Firefox.

Here's my CSS:

.section .content {
  -moz-column-count: 2;
  -moz-column-gap: 26px;
  margin: 0px;
  padding: 0px;
}

How can I get rid of the margins?

Upon request uploaded my code to jsbin. It also shows the discrepancy between the tops for the two columns. The margin doesn't show when I don't use columns.

like image 228
stevenvh Avatar asked Oct 25 '25 02:10

stevenvh


1 Answers

Your problem is very simple, you are adding CSS to content, but content contains a paragraph with a margin. Reset it to 0.

p {
    margin:0
}
<div class="section">
    <h1>Heading 1</h1>
    <div class="content">
        <p>
        </p>
    </div>
</div>

http://jsbin.com/ufobax/2/edit

like image 115
Ricardo Castañeda Avatar answered Oct 26 '25 16:10

Ricardo Castañeda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!