English 中文(简体)
How do I create an element on a page which always stays visible but moves out of the way of other elements?
原标题:
  • 时间:2010-03-01 15:57:17
  •  标签:
  • html
  • fixed

I have a HTML page which a pretty complex layout (see here). I need to put an image on that page which the visitor can drag anywhere so she can remember where she was. I ve implemented the bookmark feature but now I need to place the image somewhere where she can easily grab it.

Basically, I d like the element to stay below the ToC on the right but it shouldn t scroll out of view.

I guess I could use JavaScript to move the element as soon as it starts to scroll out of view but is there a better option? Can I say "float right and below the ToC div or view.top, whichever is greater"?

Or maybe I should create a fixed header (with the links and the maybe the ToC)?

Any other ideas?

最佳回答

It can probably be done using JQuery, but will always be jittery. I would consider a fixed DIV. Of course you could position that below the menu so it will never be higher (= closer towards the top edge) than the menu, and will maintain its position.

.thingy { position: fixed; right: 0px; top: 415px; width: 256px }

That would necessitate that there is nothing else below the menu, otherwise the bookmark icon will overlap other things.

问题回答

If you just want the image to be fixed, but still scrollable to the top of the window, then you ll need to handle the window s scroll event, and set the image s position to fixed when the image is scrolled to the top.

For an example of this, see the site navigation on QuirksMode.

Alternatively, you could give the entire TOC position: fixed; right: 0;, give the toc a width, and give the teaser a right-margin equal to the TOC s width. There would be no JavaScript requirement this way, and you d have the entire TOC always visible.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签