luke luke - 2 months ago 9
CSS Question

CSS multiple columns: column-span not working

I am using CSS to split a

main
container into several columns. This works perfectly, but the
h1
element should have a colspan. It doesn't. This is my code:

HTML:

<main class="four col">
<h1>Heading</h1>
<p>
Lorem ipsum dolor sit amet
</p>
</main>


CSS:

main
{
overflow: hidden;
width: 100%;
float: left;
}
.col h1
{
-moz-column-span: all;
-webkit-column-span: all;
column-span: all;
}
.four
{
width: 66.67%;
}
.col
{
-moz-column-count: 2;
-moz-column-gap: 1.5em;
-webkit-column-count: 2;
-webkit-column-gap: 1.5em;
column-count: 2;
column-gap: 1.5em;
}


Any idea to get this right?

Answer

Update 2:

The finally working example:

<main class="four">
  <div class="col">
    <h1>Heading</h1>
    <p>
        Lorem ipsum dolor sit amet
    </p>
  </div>
</main>

Within the same CSS from the question.


Update:

overflow: hidden; float: left; on the css main style was overriding the column-span property. Remove them, it works.


Your code works fine, it's just your CSS is a bit goofy, and the h1 should sit nested inside the classed element. Here's a working example:

HTML

<div class="newspaper">
    <h1>Heading, my glorious long heading.</h1>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius.
</div>

CSS

.newspaper
{
    -webkit-column-count:3; /* Safari and Chrome */
    -moz-column-count:3; /* Firefox */
    column-count:3;
}

h1 {
    -webkit-column-span: all;
    -moz-column-span: all;
    column-span: all;
}

Here's a jsFiddle