Solved

Absolute position div not staying at right-side of page

Posted on 2012-03-23
5
277 Views
Last Modified: 2012-08-13
I can't seem to figure this out. I want the right-side DIV to always be on the right-side of the page (not affecting the main content). It works for the most part, except if you resize the browser window less than the main content width, then the horizontal scroll-bar appears and if you then move the horizontal scrollbar the right-side DIV is no longer at the far right of the page!

It's the same for all browsers. How do I force it to be always on the right?

Float: left works, except that I can't use float as it will interfere with main body content.

Here is the minimum code to reproduce it:
<div style="position: absolute; right:0; top:0; width:100px; height:100px; background-color:red;">RIGHT-SIDE DIV</div>
<div style="width:800px; height:400px; background-color: #DCC;">
MAIN CONTENT
</div>

Open in new window


Thanks!
0
Comment
Question by:intoxicated_curveball
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:William Fulks
ID: 37759323
Go here and look at step 4. I think that's what you are wanting to do.

http://www.barelyfitz.com/screencast/html-training/css/positioning/

Basically, you need to make that floating right side positioned relative to the rest of the content, otherwise the browser just knocks it around.
0
 

Author Comment

by:intoxicated_curveball
ID: 37759392
No it didn't work, I took all their code. And the same problem occurs once I add an element with a fixed width that creates the horizontal scrollbar when resizing the browser window. Here is the new code, can somebody update the code to make it work?
<html>
<head>
<title>Untitled Document</title>

<style type="text/css" media="screen">

#div-1 {width:100%; background-color:#000;color:#fff;position:relative;}
#div-1a {background-color:#d33; color:#fff;position:absolute;top:0;right:0;width:200px;}
#div-1b {background-color:#3d3; color:#fff;}
#div-z { background-color: purple; width: 800px; }

</style>

</head>
<body>

<div id="div-1">
<p>id = div-1</p>
    
  <div id="div-1a">
<p>id = div-1a</p>
  </div>
    
  <div id="div-1b">
    <p>id = div-1b</p>

  </div>
</div>

<div id="div-z">
<p>Hello world!</p>
</div>

</body>
</html>

Open in new window

0
 
LVL 16

Accepted Solution

by:
s8web earned 250 total points
ID: 37760443
In your original example, change position:absolute to position:fixed.

<!DOCTYPE html>
<html lang="en">
	<head>
		<title>Test</title>
	</head>
	<body>
		<div style="position: fixed; right:0; top:0; width:100px; height:100px; background-color:red;">RIGHT-SIDE DIV</div>
		<div style="width:800px; height:400px; background-color: #DCC;">
			MAIN CONTENT
		</div>
	</body>
</html>

Open in new window

0
 

Author Closing Comment

by:intoxicated_curveball
ID: 37765639
Clearly I need to brush up on my CSS, this was a simple solution!
0
 
LVL 16

Expert Comment

by:s8web
ID: 37765777
Sometimes a second set of eyes catches the simple stuff. I've spent hours troubleshooting before just to have a friend look over my shoulder and tell me that a comma's missing :)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now