Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Absolute position div not staying at right-side of page

Posted on 2012-03-23
5
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Suggested Courses

721 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