2

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?

7
  • 1
    Your title is confusing! are you talking about colspan or column-span? Commented Dec 18, 2013 at 22:15
  • 1
    What browser(s) are you trying it in, column-span is not supported in all browsers: w3schools.com/cssref/css3_pr_column-span.asp Commented Dec 18, 2013 at 22:16
  • 5
    Please don't link to w3schools here, it is a site only useful for bare beginners and should never be used as a professional reference as it is a source of misinformation and bad coding practices. Please use a more correct source like MDN. Commented Dec 18, 2013 at 22:21
  • Use bootstrap for that purpose Commented Dec 18, 2013 at 22:22
  • column-span, edited that, I'm sorry to have mixed it up. I am using Safari and I know it has worked in my browser. @r3mus: I do not see the difference: I also have a container element with column-count and column-gap; and all child h1 elements should column span all columns. My Lorem ipsum content is of course longer in reality, this is just for not messing it up. Commented Dec 18, 2013 at 22:24

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

11 Comments

But it is nested inside the main container, or am I missing something?
Maybe I am blind, but I really do not see the difference: I also have a container element main with column-count and column-gap; and all child h1 elements should column span all columns. My Lorem ipsum content is of course longer in reality, this is just for not messing it up.
Call me crazy, but change <main> to <div> -- what happens?
Heh, sorry, my bad. Remove overflow: hidden; from main in your css. Didn't realize that it was applying to the element, not the class, so changing main to div dropped that style.
This helped me a lot. If I append these styles to div or to main, they don't work: overflow: hidden; width: 100%; float: left;. If I comment all of them out, it will work. If I just remove one or two of them, it won't. But I need these styles, especially the float. Any ideas?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.