2

I have an unordered list which I want split into columns, so I'm using CSS column-count on the parent div:

<h1>Mushrooms:</h1>
<div style="column-count:4">
  <ul>
    <li>Porcini</li>
    <li>Shittake</li>
    <li>Button</li>
    <li>Chestnut</li>
    <li>Oyster</li>
    <li>Portobello</li>
    <li>Crimino</li>
    <li>Chanterelle</li>
    <li>Morels</li>
    <li>Enoki</li>
  </ul>
</div>

However, for some reason this leaves a blank line in the first row of the first column:

enter image description here

How do I get my columns neat and tidy?

There is a JSFiddle

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ben
  • 4,281
  • 8
  • 62
  • 103

3 Answers3

5

The UL has a margin-top that causes the space. Set the margin-top on 0 on the UL and you're good to go.

adamk22
  • 581
  • 4
  • 18
1

make margin 0px for the ul,because browsers have default value for the ul

Maharajan
  • 178
  • 9
1

You don't need to use a div here to use column-count, you can apply directly to ul (also don't forget the vendor prefix)

besides margin (which my solve your issue) ul also have by default padding which you might want to reset.

Note: avoid use inline styles.

body {
  margin: 0
}
ul {
  margin: 0 0 36px 0;
  padding: 0 0 0 20px;
  -webkit-column-count: 4;
  -moz-column-count: 4;
  column-count: 4
}
<h1>Mushrooms:</h1>
<ul>
  <li>Porcini</li>
  <li>Shittake</li>
  <li>Button</li>
  <li>Chestnut</li>
  <li>Oyster</li>
  <li>Portobello</li>
  <li>Crimino</li>
  <li>Chanterelle</li>
  <li>Morels</li>
  <li>Enoki</li>
</ul>
dippas
  • 58,591
  • 15
  • 114
  • 126