How to set overflow hidden but without affecting certain elements - css

I have a div with overflow hidden set up in order to cut an image:
The image on the right (the device) but it's affecting the popup on the left which MUST be there.
.hero {
position: relative;
padding: 32px 0 0;
min-height: 504px;
background: #D91A37 url(../images/flagscape-bg.jpg) 0 0/cover no-repeat;
overflow: hidden;
}
That popup already has z-index applied but it is not working due to the overflow hidden on that red background div.
So, is there a way to make that rule and not touching at all the popup on the left?

You should use position: absolute for your popup so that the properties defined on the parent are not inherited by the popup.
Your code should be something like:
.popup {
position: absolute:
top: 50px;
left: 20px;
z-index: 10;
}
And provide position: relative to a general parent above hero and popup.

Related

Select / combo popup break out of overflow scroll element

We have a select/combobox component and its popup picker menu cannot break out of a parent <div style="overflow: scroll; height: 100px"> element. So essentially, the picker menu is hidden especially if the combobox is located near the top or bottom of the form.
I believe the reason is because the component uses relative positioning so that the picker can be the same size as the input:
.combo {
display: block;
position: relative;
width: 100%;
z-index: 50;
}
.combo_wrapper {
position: absolute;
background-color: red;
width: 100%;
overflow: auto;
max-height: 120px;
z-index: 50;
}
For example, in the image below, the red picker should extend outside of the blue scrolling element.
Here's a simplified demo of the issue:
https://codepen.io/anon/pen/EqaMbK
If I comment out the position: relative CSS rule, then the red popup breaks out of the parent scrolling div, however the picker width then becomes the full page width.
I can solve the problem using JavaScript by setting the picker's minimum width to the combo's width:
https://codepen.io/anon/pen/QewoBR
But I was wondering if there's a pure CSS solution.
Add overflow: visible; to the parent, it will archived what you want while not break others css rules:
.scroll-panel {
overflow: visible;
}
If you remove the overflow: auto; from .scroll-panel and replace it with position: relative; it will not be contained to the parent element but still be positioned relative to it.

Overflow Hidden for div inside a div

I have an outer div and inside it, I have an image and another div. Now, the outer div has a certain width and height and has an overflow: hidden; Now my image works fine, meaning that even though it's bigger than the div it won't overflow.
The problem i am having is with the other div that's inside the outer div. This inner div is above the image that i have. But it still wouldn't show. But after I positioned it to absolute. It worked properly.
After that I positioned outside the barriers of the outer div. Now, since I made the overflow of the outer div hidden, it shouldn't show right? Yet, the inner div shows. So here is what I would like solved.
Why wasn't the inner div showing initially and why did i have to give the div the property of position:absolute;?
Why are is my inner div still showing outside the boundaries of my outer div even though my outer div has the property of overflow to hidden.
How do I hide my inner div when its not inside the outer div. Now, note that I do not want the inner div to actually hide. I just want it not seen unless it's in my outer div.
Here is my source code for reference:
The css property of the outer div:
.banner {
width: 250px;
height: 500px;
overflow: hidden;
float: left;
margin-right: 20px;
cursor: pointer;
}
The css property of the inner div:
div.info {
position: absolute;
width: 250px;
height: 500px;
top: 0px;
opacity: 0.70;
-webkit-transition: -webkit-transform 300ms;
}
Here is a link to a jsfiddle http://jsfiddle.net/jMX3n/2/
Found the solution. I deleted the outer div with the id of #banner. And then to the .banner class, I added position: relative and then shifted the div a little. Apparently I had multiple div's similar to the inner div I was describing. In my .banner class I added the property float:left;. The overflow worked properly. Here is the new code:
The div class:
.banner {
position: relative;
top: 100px;
left: 250px;
width: 250px;
height: 500px;
overflow: hidden;
float: left;
margin-right: 20px;
cursor: pointer;
}
The inner div:
div.info {
position: absolute;
width: 250px;
height: 500px;
top: 0px;
left: -250px;
opacity: 0.70;
-webkit-transition: -webkit-transform 300ms;
}
In the fiddle, the middle div (.banner) isn't positioned, so the absolute positioning of the inner div (.info) is with respect to the outermost div (#banner), which does have position, but does not have overflow:hidden.
Therefore, in order to hide the overflow, add overflow:hidden to the outermost div as well.
UPDATED
http://jsfiddle.net/Augustus06111993/Rkgfy/
Since no Fiddle, I am taking a shot in the dark..
Since you used absolute position it will override your overflow method because
This tells the browser that whatever is going to be positioned should
be removed from the normal flow of the document and will be placed in
an exact location on the page. It is also taken out of the normal flow
of the document - it won't affect how the elements before it or after
it in the HTML are positioned on the Web page
Your outer div and inner div have same dimensions.. Try changing the css of inner div like this and you can see your image and div seperately
.info {
width: 50%;
height: 50%;
float:left;
opacity: 0.70;
}
.image {
width:50%;
height:50%;
}
.outer {
width: 250px;
height: 500px;
overflow: hidden;
margin-right: 20px;
cursor: pointer;
}

z-index causing sliding within div

FOr some reason, when I have z-index:0 for an image, the div shows correctly, but can slide up/down within the parent div. However, if I have z-index:-100 the image disappears, and no longer slides.
Is there any way to have z-index:0 without the image moving around within the parent div? I want the image to be locked into position. Thank you!
frame_th img is the div I want locked in place.
.frame_th {
width: 220px;
margin: 0px auto;
}
.frame_th img {
position: absolute;
z-index: -100;
margin: 30px 0 0px 26px;
}
Try giving .frame_th a position: relative and overflow: hidden, and .frame_th img a z-index: 0. This should keep the image positioned correctly in the parent div with no sliding.

How to put together centered text and fixed image?

I have a white page with only a 500x250 textbox and an image. The page is fluid.
I'm trying to center the textbox at the center of a page, while having a picture fixed to the bottom left of the screen. I partially achieve this with the following css:
.bottom-right { /* used to fix the image to the bottom of the screen */
bottom: 0;
right: 0;
position: fixed;
}
#content {
margin-left: auto;
margin-right: auto;
margin-top: 50%;
width: 500px;
height: 250px;
position: relative;
}
When I vertically resize the window, the image covers the textbox. I would instead like the text to go up.
If I've understood your question correctly, you need to have the "textbox" always over the image that's fixed on the bottom-right corner.
See this working Fiddle Example!
CSS
#content {
width: 500px;
height: 250px;
position: absolute; /* this is the key */
z-index: 1; /* this is the key */
left: 50%;
top: 50%;
margin: -125px 0 0 -250px;
}
CSS position:absolute;
What this does is to place the element #content outside the normal document flow, thus not being affected by other elements or having impact on the layout of later siblings.
CSS z-index:1;
What this does is to move the element up on the document stack, thus placing it over others with a lower value (the default stack level is 0).
See the CSS absolute and fixed positioning - W3C Wiki for further details.
Two options I can think of:
Use CSS media queries and if the viewport is less than a certain height then change the textbox height or position so the image doesn't cover it.
Set a min-height around the parent div and once its less than a certain height, show a vertical scrollbar.

CSS position relative and element height

I have one element below another and I am using position relative to drag the bottom element up just a bit so that it overlays the top element.
The paperOverlay element is the last element on the page, vertically speaking, and I want it to extend to the bottom of the browser window. However, the relative nudging of the element's position leaves an equal amount of whitespace at the bottom. Is there any way to avoid this?
The HTML looks like:
div class="container">
<div class="homePage">
<!-- some content -->
</div>
<div class="paperOverlay" style="position: relative; top: -70px;">
<!-- some more content -->
</div>
</div>
And the CSS looks like:
div.container
{
width: 960px;
margin: 0 auto;
}
div.homePage
{
width: 800px;
height: 500px;
}
div.paperOverlay
{
width: 960px;
min-height: 400px;
background: url('Images/Overlay.png') no-repeat top center;
}
Basically, the bottom layer is a white background with a torn paper edge effect at the top. The goal is to have the torn paper edge slightly overlay the bottom of the element above it. I did try margin-top: -70px as suggested below and it fixed the height, but now the elements in the top element lay on top of the overlay, and I want the overlay to be on top.
Could you try a negative margin rather than relative positioning? Also, could you explain a little bit more why you need to do this and post you css so that we can better suggest a solution?
Try setting the height of the paperOverlay element. It should be the actual height minus the amount moved relatively.
I did try margin-top: -70px as suggested below and it fixed the height, but now the elements in the top element lay on top of the overlay, and I want the overlay to be on top.
Try this:
div.container
{
margin: 0 auto;
width: 960px;
}
div.homePage
{
height: 500px;
position: relative;
width: 800px;
z-index: 1;
}
div.paperOverlay
{
background: url('Images/Overlay.png') no-repeat top center;
min-height: 400px;
position: relative;
top: -70px;
/* you can optionally use bottom: 70px; rather than top: -70px */
width: 960px;
z-index: 2;
}
Using position: relative; on both elements and setting the z-index should get the overlay on top of the top element, rather than the other way around.
You may also want to try using display: block; on all elements where you need fixed width/height (especially divs and other containers that need a fixed width/height, like anchors or list items), to prevent collapsing. It will usually resize non-block-level elements to fit their contents and ignore width and height rules otherwise.
Using the "vh" unit worked for me. I could not get it to work with height: calc(100%-50px)
#main-nav{
width: 55px;
background-color: white;
transition: 400ms;
height: calc(100vh - 50px);
}

Resources