Solved

Absolute position div not staying at right-side of page

Posted on 2012-03-23
5
279 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 14

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mobile version of website does not react 6 90
Fixed div within Bootstrap carousel item 11 54
HTML date format to popup calendar as soon as you click 7 39
CSS Question 9 42
"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

911 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

20 Experts available now in Live!

Get 1:1 Help Now