static top navigation with the content hiding behind it on scroll - html

Here is a fiddle as to what I am trying to accomplish: http://jsfiddle.net/60h84j7u/
I want the copy to hide below the top-nav div. I can accomplish this if the background is set to something other than transparent but in this case, the background for top-nav needs to be transparent.
HTML
<div class="wrapper">
<div class="top-nav">This needs to be at top</div>
<div class="copy"><p>This needs to hide below the top-nav as the user scrolls thru the page.</p></div>
</div>
CSS
.wrapper {
width: 500px;
height: 200px;
/*border: 1px solid purple;*/
}
.top-nav {
position: fixed;
top: 0;
border: 1px solid red;
background: transparent;
}
.copy {
position: relative;
top: 40px;
border: 1px solid green;
overflow: hidden;
}

I believe this to be impossible if you want the scrollbar to be on the edge of the browser, unless you change your design decision to make the top-nav transparent and do something else, such as adding a background colour or background image that shows the same thing.
If you add 2 fixed containers* around the scrollable part of your page, set their height to something < 100% and position them under your top-nav, you can set the outer container to hide overflow, and set the inner container to scroll on the y-axis. This does not really yield great results.
<div class="wrapper">
<div class="top-nav">This needs to be at top</div>
<div id="outercontainer">
<div id="innercontainer">
<div class="copy"><p>This needs to hide below the top-nav as the user scrolls thru the page.</p></div>
</div>
</div>
</div>
with css:
.outercontainer {
position: fixed;
top: 40px;
height: 90%;
width: 100%;
overflow: hidden;
}
.innercontainer {
position: fixed;
height: 90%;
width: 100%;
overflow-y: scroll;
}
* tested in Internet Explorer 11. Might horribly break in anything else

Related

How to show a dropdown menu outside a parent element with overflow: auto in CSS?

I have tried a lot of things and searched online but I cannot figure out the solution to this problem.
I have a div container which has a max-height, min-height and also overflow: auto. When the inner content is larger than the max-height, a scrollbar appears as expected. But, inside the content there is a dropdown, which when clicked, the menu expands, and instead of being displayed outside the parent container, it is like changing the inner content height.
The only solution I found online and made sense to me, is to wrap the container to div with relative positioning and make the dropdown absolute, but there is a big drawback now, the dropdown stays fixed on scroll, as it is absolute positioned relative to the wrapper and not the content. Is there any common way to fix this or any other solution ?
I didn't post any code because I do not want the answer to rely on my code.
I just want a minimal example if possible with these properties:
Container has a max-height
If content is larger than the container's max-height then the container should display a scrollbar.
The content has a dropdown which should scroll with every other element of the content.
The menu options of the dropdown element are escaping the container / are displayed outside the boundaries of the container.
To illustrate on my comments on the question, here's an MCVE:
.scroll-container {
border: 3px dashed #eee;
height: 400px;
padding: 10px;
overflow: auto;
width: 400px;
}
.content {
background-color: #f0f0f0;
height: 600px;
position: relative;
}
.dropdown {
background-color: orange;
position: absolute;
height: 300px;
width: 300px;
left: 300px;
}
<div class="scroll-container">
<div class="content">
<div class="dropdown"></div>
</div>
</div>
As you can see, with absolute positioning based on the relative position of div.content the orange div.dropdown creates a horizontal overflow, which is what you don't want. To fix this scenario, you need to remove position: relative from div.content and use transform: translateX(300px); instead of left: 300px;:
.scroll-container {
border: 3px dashed #eee;
height: 400px;
padding: 10px;
overflow: auto;
width: 400px;
}
.content {
background-color: #f0f0f0;
height: 600px;
}
.dropdown {
background-color: orange;
position: absolute;
height: 300px;
width: 300px;
transform: translateX(300px);
}
<div class="scroll-container">
<div class="content">
<div class="dropdown"></div>
</div>
</div>

overflow-x also hides overflow-y

There are multiple questions named this way, but I didn't find one that applies to my case, so here I am:
In this snippet:
#container:hover {
overflow-x: hidden;
}
#container {
position: relative;
width: 400px;
height: 40px;
background: red;
margin: 2em;
}
#child {
position: absolute;
bottom: 0;
}
<div id="container">
<div id="child">
a<br/>
b<br/>
hover<br/>
me
</div>
</div>
You can see that overflow-x, which is applied when you hover the red box, will also hide the overflow-y (at least on Chrome). This is annoying because I have a tooltip that I would like to be able to overflow above the red box, and in the meantime I have a menu that will slide from the right side and that should stay hidden.
Is this a bug? Is there a workaround?
You can't change the way overflow-x and overflow-y behave (it's the same in Firefox and other browsers), but you can change the way your HTML is organized.
Put everything that you want to hide when overflowing in a single wrapper. Put your tooltip in another wrapper.
Something like this may suit your needs:
#container {
position: relative;
width: 400px;
background: #f77;
margin: 3em 2em;
}
#child {
overflow: hidden;
position: relative;
}
#menu {
position: absolute;
left: 100%;
top: 0;
background: #dd2;
transition: .2s;
}
#child:hover #menu {
transform: translateX(-100%);
}
#tooltip {
position: absolute;
bottom: 100%;
}
<div id="container">
<div id="child">
hover<br/>
me
<div id="menu">
menu
</div>
</div>
<div id="tooltip">
a<br/>
b
</div>
</div>
Is the clipping behavior a bug?
No, the clipping is in accordance with the spec.
UAs must clip the scrollable overflow area of scroll containers on the
block-start and inline-start sides of the box (thereby behaving as if
they had no scrollable overflow on that side).
In your case, the "block-start" side is the top, and the "inline-start" side is the left. That's why you can put your tooltip below the content, and it will trigger a scrollbar.
#container:hover {
overflow-x: hidden;
}
#container {
position: relative;
width: 400px;
height: 40px;
background: red;
margin: 2em;
}
#child {
position: absolute;
/* bottom: 0; */
top: 0;
}
<div id="container">
<div id="child">
hover<br/>
me<br/>
a<br/>
b
</div>
</div>
So why is it possible to scroll to content overflowing below the box, but not possible to simply make it visible? The reason is that when any overflow property is set to hidden, the entire box becomes a scroll container.
[A scroll container] allows the user to scroll clipped parts of its
scrollable overflow area into view.
You can use overflow: clip, which does not turn the box into a scroll container. If you clip in both direction, you can also adjust the distance at which clipping occurs as well using overflow-clip-margin :
#container:hover {
overflow-x: clip;
}
#container {
position: relative;
width: 200px;
height: 40px;
background: red;
margin: 2em;
}
#child {
position: absolute;
bottom: 0;
}
<div id="container">
<div id="child">
aazkopekzapoekzapoekzapoekzapoekpozakepozakepozakeoza<br/>
b<br/>
hover<br/>
me
</div>
</div>

Prevent absolutely positioned child from expanding scrollable area

I have a fixed size, scrollable parent div containing two children: The first contains the content, and should determine the size of the scrollable area. The second is small overlay that is moved around dynamically, and should not affect the size of the scrollable area. That is, if the overlay overhangs the bottom edge of the content, and the user scrolls all the way down (assuming the content is larger than the parent div), scrolling should stop once they hit the bottom of the content, even if that means only part of the overlay is visible.
Is this possible to achieve?
E.g., with this HTML:
<div id="parent">
<div id="content">
<img src="640x423_image.jpg">
</div>
<div id="overlay"></div>
</div>
and this CSS:
#parent {
position: relative;
height: 400px;
width: 400px;
overflow: auto;
border: 1px solid red;
}
#overlay {
position: absolute;
height: 20px;
width: 20px;
background-color: lightblue;
top: 413px;
left: 15px;
}
(JSFiddle), the browser lets the user scroll past the bottom of the content until the entire overlay (the blue square) is visible, while I would like it to stop once the bottom of the image is visible, leaving the bottom 50% of the overlay still hidden.
For my use case, I am able to make adjustments to the HTML if necessary.
Put square box and img inside same container (#content in your case), and set overflow: hidden; on it.
#parent {
position: relative;
height: 400px;
width: 400px;
overflow: auto;
border: 1px solid red;
}
#content {
overflow: hidden;
position: relative;
}
#overlay {
position: absolute;
height: 20px;
width: 20px;
background-color: lightblue;
top: 413px;
left: 15px;
}
<div id="parent">
<div id="content">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAFBQUFBVUFpkZFp9h3iHfbmqm5uquf/I18jXyP////////////////////////////////////////////////8BUFBQUFVQWmRkWn2HeId9uaqbm6q5/8jXyNfI///////////////////////////////////////////////////CABEIAacCgAMBIgACEQEDEQH/xAAYAAADAQEAAAAAAAAAAAAAAAAAAQIDBP/aAAgBAQAAAADnG4vowbzG0y3fNV4o16crpU2QkqdZuiWm+eL6JBMZDuJSw0DSiOd2QLTUmZllzchaxH0isptmOmGxSigQN80b6IBA41JM4z2ktXjkO04vSs1FICiL1wg03mqljdYXn0BDqUBc809NyyUMTJRk7RU6c8UrlBoOFQ5LUUZj6kiqAFA9QiqSBVHOutDQIjRCh4bKNAfOm6kqW3Fzcgo6DBGnVlcU3SM0rsSZSQzPF9kAIJLZOeRaWooyWsJ0yGTRtlRC1jMN2a522qrm0y6B5sYItYZ67xQIuHSMpw2I0pnPBrMMdJDTpOsNXgF6jb0G87wudWoZVZhb5J6xUMVZXUqIz3WHSkcobZXAOWFVGjmN8cx9VYWXaQ4J1pKWUkNvjrrhsps59KlHLsTn0xMYl3FPPSHFgJ1n0rlDTdQ9FQ6zx0Ww87TqUqefPr0Z0FO559GSc3ZnnlsljJrNCm7zSGqRXThgPXowudoubrLGq3UjToi2ckb6puabWNjnF65zO6z5x6xoKnlNDeW0xtvwo001lDm1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ZFj7FxbpN5WN4985sXYtI8r6QuMnSZHUXhdDdYfefH2NiGx4Q8LDEreG+C6xHsbyssekR6FiT1wZHLE6ELj5HrK7xY2Lk3obILE3cmQW+M2S1HCJYfefH7xY3h9cFhkS+a4LhLNjI95Yus0NURFiyyybt4QssXKfWILQ3SePHhZ7kTEXhD7eYe8vEnzQ+CHhfR74MiXyseEy83ldCLRePkfIssssm8zlrEeuG0iJLsXY8IfbzHvF5f2L6m83lfUnwbyuV4vLYu8T5SehdDIj5Lv6n914v8AoPCy/uYu8Psjmyx5WXwXB/Q+C/418bw3i8L71wf2L7b5X9bf02XjReKKHhfQua/u1/XWHworNDwuvseVl/auNfWs3xvhvi+F8tl5eFyrhZY/tfJZv/hXi+Flll/1N/1LL+topi4ULNYpizrNFFcHmuFfTXFL94f9DT5bwvrrF539eyhrFcXrFor6nimUkXl/Q/o6eUWP7/R6KwiilijYi2PjZrKebwyy89vnZbKbxf2V/QWVzXLvLd5f/priudovlX0W/wCokltiwuV/V0a5rHRa4UihcL4b+my839lcq+yvrby8oVm7ymXfrlZfFGsaLNF4s0NYfF/2lzrksddZvFmsJ2MT5XwVfS8t8KX7/r64P7axeLviimW8Xy0f+PO7GWbLKy8rlf8Abv6VwsvhZYxF6O+V49YYiuK4b+l81/wKZvhZXG+LWGexl42PNZZviy8X/wAOjrFNf1ErKxWNI7zQjRZY+i8XzvNPNcv/xAAUEQEAAAAAAAAAAAAAAAAAAACg/9oACAECAQE/AAcf/8QAFBEBAAAAAAAAAAAAAAAAAAAAoP/aAAgBAwEBPwAHH//Z">
<div id="overlay"></div>
</div>
</div>

How to eliminate whitespace when scrolling [fixed sidebar]

Let me first try to illustrate the problem
I have a webpage which contains a header and a sidenav. The sidenav is fixed in css, since I don't its content to move when scrolling.
When the page isn't scrolled down it works as intended, somewhat like this
However when I scroll i don't want whitespace on top of the sidenav. Currently when I scroll down the page, it looks somewhat like this
The intended behavior should be something like this
How do I go about this in css? Do I mess with the z-index of the elements? so the sidenav is behind the header when the page isn't scrolled? Or do I dynamically add to the sidenav's size when scrolling?
And how would either of these options be done in css?
As I understand, you have to set z-index of the header higher than the sidenav
Stack Snippet
.header {
height: 100px;
background: #000000;
position: relative;
z-index:999;
}
body {
margin: 0;
}
.sidebar {
position: fixed;
left: 0;
top: 0px;
width: 100px;
background: red;
height: 100%;
padding-top:100px;
}
.content {
height: 1000px;
background: yellow;
}
<div class="header"></div>
<div class="main">
<div class="sidebar"></div>
<div class="content"></div>
</div>

Absolute positioned div breaks on relative parents edge

I am experiencing some trouble while positioning an absolute div inside a relative one. I want my absolute div (inline-block) to grow until it reaches a given px-amount (max-width). This works as expected, until I add a width (smaller than the max-width of the absolutes div) to the relative div.
I want the text in the absolute-div to break at the max-width (400px) and not at the edge of the relative parent div (300px).
When giving white-space: nowrap, the words just flow over the absolute divs end.
Have anyone an idea how to solve this?
Thanks!
See:
http://codepen.io/anon/pen/KVJvmZ
html
<div class="relativeContainer">
<div class="absoluteContainer">
Hello you! This breaks on relativeContainers edge.. This is not what i want. It should just go further an further (until it reaches max-width of 400px).
</div>
</div>
<div class="relativeContainer">
<div class="absoluteContainer">
This should stay small.
</div>
</div>
css
.relativeContainer {
width: 300px;
height: 100px;
border: 1px solid black;
position: relative;
margin-bottom: 50px;
}
.absoluteContainer {
display: inline-block;
position: absolute;
top: 0;
left: 0;
max-width: 400px; /* Word-break should happen here. */
border: 1px solid red;
}
I am afraid it is not possible to solve this issue with your markup. But there is light at the end of the tunnel: You could change your markup or use javascript to achieve what you want.
Depending on your requirements, this could help you: http://codepen.io/anon/pen/eJXYOJ
html
<div class="relativeContainer">
<div class="absoluteContainer">
<div class="contentContainer">
Hello you! This breaks on relativeContainers edge.. This is not what i want. It should just go further an further (until it reaches max-width of 400px).
</div>
</div>
</div>
<div class="relativeContainer">
<div class="absoluteContainer">
<div class="contentContainer">
This should stay small.
</div>
</div>
</div>
css
.relativeContainer {
width: 300px;
height: 100px;
border: 1px solid black;
position: relative;
margin-bottom: 50px;
}
.absoluteContainer {
position: absolute;
width: 100vw; /* do a large number of px for ie8 compatibility*/
top: 0;
left: 0;
background-color: lightgray; /* just to show you what I've done*/
}
.contentContainer {
display: inline-block;
max-width: 400px; /* Word-break should happen here. */
border: 1px solid red;
}
Absolute container is directly related to the relative parent container.
There is no way to make an absolute container bigger (width or height) than a relative parent container.
If you want an absolute container bigger (width or height) than his parent the parent should not be relative.
Hope this help.
Have a good one
I don't think what you want to do is possible without using another class, or using JS. Here's how you can do it with css:
<div class="relativeContainer">
<div class="absoluteContainer bigger">
Hello you! This breaks on relativeContainers edge.. This is not what i want. It should just go further an further (until it reaches max-width of 400px).
</div>
</div>
<div class="relativeContainer">
<div class="absoluteContainer">
This should stay small.
</div>
</div>
.relativeContainer {
width: 300px;
height: 100px;
border: 1px solid black;
position: relative;
margin-bottom: 50px;
}
.absoluteContainer {
display: inline-block;
position: absolute;
top: 0;
left: 0;
max-width: 400px; /* Word-break should happen here. */
border: 1px solid red;
}
.absoluteContainer.bigger{
width: 400px;
}
I have looked at your example and I don't think you can do what you want if the absolute is inside the relative and you don't specify a width. Currently, with only a max-width, the inner absoluteContainer has no reason to go outside the relative container so it won't. Once you set a width, you get what you want but the small cannot stay small! You might be able to 'spoof' what you want by locating the absolute outside the relative but in the same location. This gives you something of what you want - but it won't (say) scroll the relative one if the absolute is bigger.
Example at: http://codepen.io/anon/pen/Nxovey
If you don't want to (or can't) identify longer text in CSS with extra classes then this is the best you can do without javascript.
Code:
<div class="spoofContainer">
<div class="absoluteContainer">
Hello you! This breaks on relativeContainers edge.. This is not what i want. It should just go further an further (until it reaches max-width of 400px).
</div>
</div>
<div class="relativeContainer">
</div>
<div class="spoofContainer">
<div class="absoluteContainer">
This should stay small.
</div>
</div>
<div class="relativeContainer">
</div>
CSS:
.spoofContainer {
width: 400px;
height: 0px;
overflow: visible;
position: relative;
}
.relativeContainer {
width: 300px;
height: 100px;
border: 1px solid black;
position: relative;
margin-bottom: 50px;
}
.absoluteContainer {
display: inline-block;
position: absolute;
top: 0;
left: 0;
max-width: 400px; /* Word-break should happen here. */
border: 1px solid red;
}