Solved

Absolute position div not staying at right-side of page

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
<div class="clearfix"></div> not working on home slider 5 26
Are these icons a web font? 3 29
Can't get cursor to change 3 21
CSS Odd/Even Confusion 2 42
CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

752 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