tags:

views:

177

answers:

3

I am creating a horizontal webpage and I am trying to make the body dynamically expand according to the content within it.

I am building the website here: http://www.obliquo.co.uk/

As you can see it all works, but I am forced to setting a huge body width in pixel value. The content on the page will be changing all the time. If I don't set a width in pixels, the divs start bumping vertically, naturally.

A: 

Your best bet would be to calculate the width the screen should be every time its changed using JS and then applying that value to the body's width attribute, again using JS.

Danten
A: 

Since you are already using jquery, you can do the following .. I tried it in IE8 and it works. You might have to tweak it a little for other browsers.

Add the script tag in your and this should do the trick, if you are planning on having the LINKS as your last section on the page. If you change that, you might have to play arround to make it more dynamic, but this is the basic principle that I would follow.

<script type="text/javascript">
            $(document).ready(function()
            {
                var width = $("#links").width() + $("#links").position().left;
                $("body").css("width", width + "px");
            });
</script>
drusnov
I guess I need to be better at reading questions .. since your content would be changing all the time, I would use this in a function that you can call and implement with some kind of OnContentChange trigger .. that way it will do the calculations when you need them instead of just on document ready .. hope this helps.
drusnov
Thanks guys, it seems that there is no way for a nice simple CSS3 command to do the job, so jquery it will have to be. I am worried it will be quite complicated with paddings and margins to account for, but I have set a max number of divs. Thanks for the responses, I was looking online for ages, and it appears I wasn't being totally silly this time around!
danixd
A: 

I haven't taken the time to fully understand your HTML, but assuming the following structure:

<div id="container">
    <section>...</section>
    <section>...</section>
    <article>...</article>
    <article>...</article>
    <section>...</section>
    <section>...</section>
</div>

use the following CSS:

#container {
    white-space: nowrap;
}
section, article {
    display: inline-block;
    white-space: normal;
    /* no float */
}

This will allow each section/article to flow as an inline element would (i.e., wrap). But the white-space: nowrap declaration prevents the wrapping and keeps it on the same line.

Casey Hope