/    Sign up×
Community /Pin to ProfileBookmark

Fixed Width Centred Div Scrolling issue

[URL=”http://www.neoterik.com.au/testing_barossaearth/test.htm”]Example Here[/URL]

If I have a fixed width .panel div inside a full width .wrap div, styled like so

[code]
.wrap {
width: 100%; overflow: visible;
}
.panel {
width: 780px; height: 100%; overflow: visible; position: relative;
margin: 0 auto 0 auto;
}
[/code]

Then inside the .panel div i place another element (another div for arguments sake) like so

[code]
<div class=”wrap”>
<div class=”panel”>

<div class=”test”>test</div>

</div>
</div>
[/code]

and style it like so

[code]
.test {
width: 200px; height: 200px;
background-color: red;
position: absolute;
top: 0px; left: -100px;
}
[/code]

it behaves as expected, the .test div half ‘hangs out’ of the parent .wrap, but if i scale the browser window below 780px, horizontal scrollbars appear that allow you to scroll only to the left edge of the .wrap div

this is the behaviour i want.

but! if i use “right: -100px;” instead, to ‘hang’ .test outside of .wrap on the right side, for some reason, IE6, IE7 and FFox all create horizontal scrollbars that allow me to scroll to the extremities of .test, and not just to the right edge of .wrap…

why is this? and how do i stop it? i want to see the part of .test that is sticking out, but only if the browser window is wider than .wrap’s width…if the browser window is smaller, i only want the horizontal scrollbar to allow for scrolling across the width of .wrap

i find it strange that it behaves how i want on the left side, but not on the right side.

anyone have any advice/info?

to post a comment
CSS

13 Comments(s)

Copy linkTweet thisAlerts:
@WebJoelOct 09.2007 — I am not following this... what effect are you after?

Try this:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" id="index">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<style>
body, html {
margin: 0; padding: 0; border: 0;
width: 100%;
font-family: Georgia, serif;
background-color: #59464B;
}
.wrap {
width: 100%; overflow: visible;
height: 500px;
}
.panel {
position: relative;
[B]width: auto;[/B] /* 'full-width' auto-resizing: better than '100%' */

height: 500px; overflow: visible;

background-color: blue;

margin: 0 [B]100px[/B] 0 [B]100px;[/B] /* compensate for absolute-positioned blue "test" and "test2" boxes */

}

.test {

width: 200px; height: 200px;

background-color: red;

position: absolute;

top: 0px; left: -100px;

}

.test2 {

width: 200px; height: 200px;

background-color: red;

position: absolute;

top: 0px; right: -100px;

}

</style>


</head>

<body>

<div class="wrap">

<div class="panel">

<div class="test"></div>
<div class="test2"></div>
</div>
</div>


</body>

</html>[/QUOTE]
Copy linkTweet thisAlerts:
@WebnerdOct 09.2007 — Well you certainly can't scroll from right to left as everything on computers draw from top - left. What you want to achieve is basically, "a left handed users approach". You need to set your [b]overflow:hidden[/b] on your body to get the effect you are looking for.

Of course, this may change some other things on your page. So, you may even need to <script> your solution to test when the window is smaller than a certain width, and then, crop the <div> as necessary
Copy linkTweet thisAlerts:
@matthewjumpsoffauthorOct 10.2007 — overflow hidden is not a solution - i want child elements to be [I]visible [/I]- just i dont want them to trigger any horizontal scrolling, no matter that they are outside their parent div

i cant seem to work out how to stop this - i kinda get why its happening, but yea i just wish there was some way to stop it

like i said - all i want to do is be able absolutely position elements outside a parent which has a fixed width, and simply have the browser ignore the outside elements when it comes to scrolling
Copy linkTweet thisAlerts:
@WebJoelOct 10.2007 — -Sounds to like an accessibility nightmare... content that is 'displayed' off the right edge of a user's viewport and no method to 'scroll' (read" "access") the content... ? If this is the case, 'position:relative;' the container, 'position:absoute;' the blue boxes and being 'absolute', they are out of the document flow anyway and quite effectively 'off the screen' and ignored by the shell (which would create the scrollbar).
Copy linkTweet thisAlerts:
@matthewjumpsoffauthorOct 10.2007 — the reason i want to do this is because the elements do not contain any content at all - they contain drop shadow background-images, purely presentational...also they are added on the fly using javascript/DOM - i want appended border elements to be as transparent as possible and not mess up the parent element

your suggestion of positioning the container and the boxes doesnt work - thats already exactly what im doing, and as i said, if the element is absolutely positioned outside of its parent on the right, the browser refuses to ignore it...while if its outside on the left, the broswer ignores it for scrolling

test it - and if you can get it working like you said, i would appreciate a look at your source ?
Copy linkTweet thisAlerts:
@WebnerdOct 10.2007 — If you ae already using Javascript, then just fix the width of the element to keep the element on screen when it is generated.
Copy linkTweet thisAlerts:
@matthewjumpsoffauthorOct 10.2007 — fix the width of which element? the container? or the absolutely positioned child?

im pretty sure fixing the width of either using javascript or CSS doesnt change anything, since overflow: visible must be set on the parent to stop the children from being hidden

i could make some script that runs every time the browser is resized but that is seriously messy - there surely surely has to be a way to trigger the browser to be obedient using just CSS...

i was under the assumption that the absolutely positioned children, being out of the natural flow, would not trigger any scrolling, well so far im 50% right, if its absolutely position on the top or left, no scrollbars appear - cursed right and bottom sides tho...
Copy linkTweet thisAlerts:
@WebJoelOct 10.2007 — Do you have a URL that works? I am not understanding the effect that you are after. I think you're trying to re-invent the wheel here... a 'dropshadow' can be created 'on the fly' and not even with javascript, and no 'child container' is required to do so. It can be applied to the 'parent container' and as thus, be considered part of the whole 100% width.

Not to mention, really nice CSS-only drop-shadow effects can be created too.
Copy linkTweet thisAlerts:
@matthewjumpsoffauthorOct 10.2007 — im writing a javascript function that finds any element with a certain class, then appends 8 spans into the element, 4 containing tiling background images that are absolutely positioned top, left, right and bottom, and 4 that contain no-repeat corner images that are absolutely positioned, surprisingly enough, in the corners

which all works perfectly already, all i need to do to apply a photoshop style border to anything is to add "setBorder" to its class

like i said, it works fine already, the only problem is i am of course using negative absolute positioning to place the borders just outside the parent element, and this stupidly makes scrollbars appear, but only the right and bottom sides...

all im thinking is - [B]something [/B]must be telling the browser not to create scrollbars if an absolutely positioned child falls outside the left or top - so what property(s) is it - and how can i control it

WebJoel im yet to find an on the fly CSS antialised, smooth drop shadow/border solution that doesnt require you manually fill your html with loads of crap...this way the html source stays clean and the 'crap' is in the javascript once, then gets applied where needed.

theres probably other js solutions out there, but im writing one all the same ?
Copy linkTweet thisAlerts:
@WebJoelOct 10.2007 — I have yet to see your javascript. So far, all you've posted is CSS and HTML, -and the URL is broken. :o

I'll look at this again tomorrow but I am beginning to suspect that what you are doing is beyond my ability to be of any help. :rolleyes:

I am almost sure that this will be of no help either:

*js[CODE]/* default setup that everything sees */
.shadow {
/* needed for Internet explorer */
height: 1em;
filter: Shadow(Color=#666666,
Direction=135,
Strength=5);

/* Needed for Gecko */
line-height: 2em;
white-space: nowrap;
}

/*
* used by browsers which know about
* :before to create the shadow
*/
.shadow:before {
display: block;
margin: 0 0 -2.12em 0.15em;
padding: 0;
color: #666666;
}

#shadow_1:before {
content: 'In shadow';
}
#second_2:before {
content: 'Happy Shadowing!';
}

/**/
html*.shadow {

[color:red;/* required by Safari
* so that [] is correctly
* begun. associated with
* the property, yet hiding
* it. Seen by IE6 */

/*
* seen by IE6 and Safari, but hidden
* from Gecko
*/
text-shadow: #666666 5px 5px 5px;

]color:auto; /* resets color for IE6 */
}/**/

/*
* end hack using dummy attribute selector
* for IE5 mac
*/
.dummyend[id]{clear: both;}

/**/
html*.shadow:before {

[color:red;/* required by Safari.
seen by IE6 */

/*
* seen by IE6 and Safari, but hidden
* from Gecko
*/
display: none;

]color:auto; /* resets color for IE6 */
}/**/

/*
* end hack using dummy attribute selector
* for IE5 mac
*/
.dummyend[id]{clear: both;}[/CODE]
html:[code=html]<h1 class="shadow">Shadowed text, etc..</h1>[/code]

class="shadow" can be applied to a container, an image, etc... not just 'text'..
Copy linkTweet thisAlerts:
@matthewjumpsoffauthorOct 11.2007 — sorry yea i took the example down - but that doesnt contain any javscript anyway...

thanks for the example WebJoel - but i cant seem to get it to work properly - it appears in IE7, but broken - and it doesnt do anything in Ffox2 or IE6?

unfortunately you are correct, that doesnt help ? the point of what im doing is so that i can simply take any photoshop design, cut up the borders into images, and easily apply the border to anything - that way i can get any effect i want, or that a designer supplies me in their concept...

the thing that sucks is that my code works beautifully so far, its a breeze to create any kind of fancy border or drop shadow, except for the fact that the added elements cause scrolling on the right and bottom

im intending to make this as portable and modular as possible so anyone can easily use it - but this issue makes it a lot less transperant a solution than is acceptable...
Copy linkTweet thisAlerts:
@WebJoelOct 13.2007 — , cut up the borders into images, and easily apply the border to anything - .....[/QUOTE] We have something to look forward to, -CSS3. That will allow images to be used as borders. e.t.a. for CSS3 is 10-years away still, maybe... :mad:

I'm not big into 'cutting up images into pieces' and building a site from that. I much more prefer using CSS to build a site, and using images to 'background' whatevers. Cleaner, no 'cutting up & pasting back together'. ?

I'll check that code to see why (or even if) it doesn't seem to work for you. Possibly it is IE-only. I know it worked for me in IE6.
Copy linkTweet thisAlerts:
@matthewjumpsoffauthorOct 14.2007 — We have something to look forward to, -CSS3. That will allow images to be used as borders. e.t.a. for CSS3 is 10-years away still, maybe... :mad: [/QUOTE]
i am aware of the lovely new features of CSS3 - but seeing as i dont plan to halt designing and building websites for 10+ years ...

I'm not big into 'cutting up images into pieces' and building a site from that. I much more prefer using CSS to build a site, and using images to 'background' whatevers. Cleaner, no 'cutting up & pasting back together'. ?
[/QUOTE]

im very happy for you ? i use CSS to build all my sites, but certain bits and pieces that add 'flavour' require a bit of trickery...standard background images dont scale with extra content for instance, which is vital especially for a CMS or similar solution...

I'll check that code to see why (or even if) it doesn't seem to work for you. Possibly it is IE-only. I know it worked for me in IE6.[/QUOTE]
cheers, but dont worry too much about it. call me a stubborn bugger but i still want to work out how to get around the issue i raised, its constantly in the back of my mind nagging me...i appreciate the effort though, its just i have a one-track mind ?
×

Success!

Help @matthewjumpsoff spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...