How to check which div is visible while scrolling?

How do I center my div layer?

  • I have an iframe that works perfectly fine. I am trying to layer it on top of my website layout but I can't get it to center and its making me really mad. When I use: <div style="position: absolute; top:110; left:475"><IFRAME name="inline" src="2.html" background-color="000000" width=960 height=590 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto style="FILTER: chroma (color=f1dd97)"></IFRAME></div> It works. The only problem is that in different screen sizes and browsers, it looks off, because it's formatted for my screen. So I want to center align it so that no matter what, it's always centered horizontally, but from the top I still need it to be 110px. Can someone help me? It's driving me nuts!!

  • Answer:

    This will work <style type="text/css"> #container { width: 960px; background: #FFFFFF; margin: 0 auto; border: 1px solid #000000; text-align: left; margin-top:5em; } #mainContent { padding: 0px; } </style> <div id="container"> <div id="mainContent"> <IFRAME name="inline" src="2.html" background-color="000000" width=960 height=590 scrolling=auto style="FILTER: chroma (color=f1dd97)"></IFRAME> </div> </div>

Alee at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

margin-left:auto; margin-right:auto; you usually want to stay away from pixels when centering unless you wana push it to a corner you could do. position: aboslute; right:0px; to shove it to the right. <div style="position: absolute; top:110; left:475;MARGIN-LEFT:AUTO;MARGIN-RIGHT:A… <IFRAME name="inline" src="2.html" background-color="000000" width=960 height=590 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto style="FILTER: chroma (color=f1dd97)"> </IFRAME> </div>

OrgasmicOreo

html <div id="center_frame'><IFRAME name="inline" src="2.html" background-color="000000" width=960 height=590 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto style="FILTER: chroma (color=f1dd97)"></IFRAME></div> the CSS #center_frame { margin: 110px auto; }

person

<div style="margin-top:110px; align: center;"> try that

george

here is the css to center the div with an absolute positioned element. Everyone else is telling you how to do it with an element without absolute positioning. #iframe_div { position: absolute; width: 960px; height: 590px; top: 110px; left: 50%; /* This will position the div at 50 percent left of the screen. However the starting point will always be at 50% so we need to deduct half of the divs width to make it center to do this divide the width by 2 so 960/2 = 480. Then give it a negative margin on the left by 480px. That should center an absolute positioned div */ margin-left : -480px; } if you don't use css in a separate file than you can style it the way you did it <div style="width: 960px; height: 590px; position: absolute; top: 110px; left: 50%; margin-left: 480px;"><IFRAME name="inline" src="2.html" background-color="000000" width=960 height=590 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto style="FILTER: chroma (color=f1dd97)"></IFRAME></div> Hope that helps

Joseph McMurray

To center a container, you can not use absolute positioning. You can, but tweaking it into position is a waste in time. Just add a width and use: margin: 0 auto; That will center an element with a width. <iframe name="inline" src="2.html" style="display: block; background: #000; width: 960px; height: 590px; margin: 0 auto; overflow: auto; FILTER: chroma (color=f1dd97);" frameborder="0"></iframe> If that doesn't work for you, maybe: <div style="width: 960px; height: 590px; margin: 0 auto; overflow: auto;"> <iframe name="inline" src="2.html" style="background: #000; width: 960px; height: 590px; margin: 0; overflow: auto; FILTER: chroma (color=f1dd97);" frameborder="0"></iframe> </div> Ron

Shadow Knows

<div style="width:200px; margin-left:auto; margin-right:auto;"></div>

erry

create the layer

Anna

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.