tags:

views:

142

answers:

5

I'm working on an app where we insert our app's widget into the body of a site, at the bottom. We made it so that the widget's position is fixed, with bottom: 0. The widget would persist no matter where you are on the site; that is, it's at the bottom of the viewport. The trouble is that the widget covers elements at the bottom of the site.

Is there any way I can push the site's content up, regardless of its content's positioning (e.g. position and float properties), such that our widget will never cover anything on the site? Because of the widget's "position: fixed", it breaks out of normal layout, and thus putting a margin- or padding-top won't do anything.

I've tried the temporary solution where I add a div before the widget itself that's the height of the widget, so it pushes everything up and out of the way. However, if the site itself has floated or bottom-positioned elements, those will be covered up anyways.

Update: Thanks for all the answers. In the end, I pretty much gave up on this task, since it seems to be site-specific, and the widget is meant to be embedded on any site through a <script>. Guess I should have said that beforehand.

Update 2: Last answer solved it.

A: 

Have you tried inserting your widget at the very bottom of the <body> tag? It would be at the bottom of the page and not need to be position:fixed. It won't cover any content because it would follow normal flow.

Zack Mulgrew
The thing is, I want the widget to persist whereever you are on the page. So putting it at the bottom won't do if I'm at the top of the page; I want to see the widget at the same time.
curagea
I see. Indeed this is a tricky situation! Is JavaScript a viable solution? Even an elegant JavaScript solution, pushing elements out of the way is going to be difficult.
Zack Mulgrew
+2  A: 

You could perhaps add a padding-bottom to the body that is equal to the height of your position: fixed element.

gnarf
A: 

You must continue using the positioning of your widged absolute, and the put a div for the content and add a margin-bottom equal or more the height of your widged.

That would work, I guess.

José Leal
A: 

Create an empty margin that runs the height of the page:

<style>
#content {width: 80%;
          margin-left: 18%; /* to create a gutter between content and widget 
                               and to allow for borders and such */
}

#widget {width: 18%;
         position: fixed;
         bottom: 0;
         left: 0;
         padding: 0.5%;
         border-top: 1px solid #ccc;
         border-right: 1px solid #ccc;
}

</style>

...

<div id="content">

    <p>All of the branding, headers and content goes in this wrapper div.</p>

</div>

<div id="widget">

    <p>Widget goes here.</p>

</div>

...

Should work, I think. Mainly because it creates a column for the widget to slide in. Note: you may need to allow for small screens, so possibly create some means for the widget to not be pushed down, or at least accept a graceful deprecation.

David Thomas
The code looks like it places the widget on the side of the content, rather than below. Also, we don't have control over the site itself; the widget is something that people can insert in their own sites.
curagea
+1  A: 

In jQuery:

$('html').height( $(document).height() + numerical_height_of_your_widget );

This basically sets the height of the html tag to be the sum of the height of the content (via jQuery's magical $(document).height() and the height of whatever position: fixed element you're adding (in this case, your widget).

avk
I successfully tested it on a variety of layouts: http://www.cssplay.co.uk/layouts/three-column-layouts.html http://www.intensivstation.ch/en/templates/ http://www.opensourcetemplates.org/
avk