Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS 2 column layout question

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #26193
    andrews
    Participant

    Hi,

    Does anyone know how to make a 2 column layout flexible where if the 2nd column doesn’t have any content, the first extends full width? I could of course set a class on the first column like "full_width" and assign it a different width, but I was hoping I could solve this without the use of a class.

    Cheers

    Andrew

    #64507
    Chris Coyier
    Keymaster

    Great question. I’d probably approach it with jQuery…

    Right sidebar = fixed width, float right.

    Left content area = float left, no width. (use an inside div if you need to force width on the content area)

    Code:
    var test = $(“#sidebar”).html();

    if (test = “”) {
    $(“#sidebar”).remove();
    }

    Although… now that I think about it more, if the sidebar doesn’t have any content anyway, it might not need to be removed since it’s height will collapse to zero (assuming it doesn’t have any padding).

    With the sidebar gone or collapsed, the left content area should theoretically expand to full width. If there is problems there, you could…

    Code:
    var test = $(“#sidebar”).html();

    if (test = “”) {
    $(“#sidebar”).remove();
    $(“#content”).css({ “width”: “100%”, “float”: “none)
    }

    #64531
    andrews
    Participant

    cheers, I’ve really got to start learning jQuery..

    #64545
    tmjacsone
    Member

    yes, jQuery is very powerful, and mean while, it is quite light weight

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘CSS’ is closed to new topics and replies.