absolutely positioned content is not displayed inside angular ui-router ui-view - html

I have here plunkr which shows the issue I am facing.Basically I am trying to do create a scroll bar for middle div element, have all three div's fit inside the page.
This approach works fine if I use it as html page, but when I use it inside ui-view, the content inside '#content-scroll' does not show up, if I remove position:absolute from CSS, it displays, but doesn't display scroll bars.
Basically I just want to know how can I have the content display?
How can this be resolved?
http://plnkr.co/edit/ZkGafJ8cS6VG6lfS9SJY?p=preview
#content-scroll {
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
overflow: auto;}
Here is the example of same page that works inside html
http://jsfiddle.net/sA5fD/8/

absolute positioned elements behave according to it's parents.
If we give bottom:0; top:0; to an absolutely positioned element it will select the bottom and top of it's parent. So:
Your previous example it is working since the parent have 100% height.
Inside ui-view it will not work it doesn't have an explicit height to it.
There's more than one solution to this problem. For example I applied a min-height to the parent #content and changed it's display property. I suppose you have #content only used for this scrollbar content. Othewise you have to apply special class to the element.
#content {
display:block;
height:100%;
background:#8f8;
min-height: 90vh;
}
Here's a plunker: http://plnkr.co/edit/5vl0AN3WwtUJmDiNtNdL?p=preview

I guess This would solve your problem.
html { height: 100%; }
body {
padding:0 0;
margin:0 0;
height: 100%;
}
#main {
display:table;
height:100%;
width:100%;
}
#header, #footer {
display:table-row;
background:#88f;
left:0;
right:0;
}
#content {
display:table-cell;
height:100vh;
background:#8f8;
}
#content-scroll-wrap {
position: relative;
height: 100%;
}
#content-scroll {
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
overflow: auto;
}

Related

box-sizing: border-box not working as expected [duplicate]

i have 2 divs and a dl:
<div id="wrap">
<div id="header">
<dl id="site_nav_global_primary">
and this is my style:
#wrap {
margin:0 auto;
width:100%;
min-width:760px;
max-width:1003px;
overflow:hidden;
}
#header {
width:100%;
position:relative;
float:left;
padding-top:18px;
margin-bottom:29px;
}
#site_nav_global_primary {
float:right;
margin-right:18px;
margin-bottom:11px;
margin-left:18px;
}
Now i want to change site_nav_global_primary to have a full screen width without
changing the wrap and the header. but when i try:
#site_nav_global_primary {
position: absolute;
width:100%;
top:0px;
left:0px;
}
The navigation gets the 100% of the wrapper which is max 1003px width. i want it to
stretch to the maximum without changing the wrap and header divs.
Is this possible?
You could set both left and right property to 0. This will make the div stretch to the document width, but requires that no parent element is positioned (which is not the case, seeing as #header is position: relative;)
#site_nav_global_primary {
position: absolute;
top: 0;
left: 0;
right: 0;
}
Demo at: http://jsfiddle.net/xWnq2/, where I removed position:relative; from #header
You need to add position:relative to #wrap element.
When you add this, all child elements will be positioned in this element, not browser window.
I have similar situation. In my case, it doesn't have a parent with position:relative. Just paste my solution here for those that might need.
position: fixed;
left: 0;
right: 0;
Adding the following CSS to parent div worked for me
position: relative;
max-width: 100%
Make #site_nav_global_primary positioned as fixed and set width to 100 % and desired height.
This one also works. With this method, there is no need to interfere with positioning of parent divs. I have checked
#site_nav_global_primary {
position: absolute;
width: 100vw;
}
I don't know if this what you want but try to remove overflow: hidden from #wrap

HTML LAYOUT (Basic) - CSS issue

I'm having a small css issue with a basic html layout .
What is want is this : (without content)
http://jsfiddle.net/cge89ef4/1/
With content : http://jsfiddle.net/cge89ef4/2/
As you can see , the footer remains stuck and does not go to the bottom of the page as i want it too.
CSS :
body {
background-color: blue;
color:red;
margin: 75px auto 50px;
height:100%;
}
div#fixedheader {
position:absolute;
top:0px;
left:0px;
width:100%;
height:75px;
background:yellow;
}
div#fixedfooter {
position:absolute;
bottom:0px;
height:50px;
left:0px;
width:100%;
background:black;
}
Any way to fix it ?
Thanks
UPDATE
I have changed the DOM to HTML5 Tags for Header and Footer , I have also added a little JavaScript that reacts to the window resizing.
So IF your window height is more than the document height the footer is positioned absolute to the bottom, IF not the footer is positioned FIXED above the content
Also if you scroll down and the header is not visible any more it becomes fixed above the content as well
http://jsfiddle.net/cge89ef4/8/
UPDATE END
Here http://jsfiddle.net/cge89ef4/3/
change absolute to fixed for footer
position:fixed;
If you dont want the footer to overlap your content at any time you should add a margin or padding bottom to the content container with the height of the footer.
In addition you could look intho HTML5 tags , because there are already preset tag names for header, footer etc
For exampe:
<header></header>
<article><section></section></article>
<aside></aside>
<footer></footer>
use this styling for your body
body{
position: relative;
margin: 0;
}
Just make sure you give position: fixed to header and if you want the footer not to be fixed all the time, use a min-height.
body {
background-color: blue;
color: red;
margin: 75px auto 50px;
height: 100%;
}
div#fixedheader {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 75px;
background: yellow;
}
div#fixedfooter {
position: fixed;
bottom: 0px;
height: 50px;
left: 0px;
width: 100%;
background: black;
}
Fiddle: http://jsbin.com/behajakuse/1/edit?html,css,output
have the body position: relative;

Absolutely Positioned Elements not In Place when in Actual Code

I'm trying to contain 2 images and some text to a div. I have it positioned the way I'd like, but when adding it to my site it's positioned in the top left corner.
How do I get it so it sits in a div by itself under the rest of my content and doesn't move to the top left of my website?
I created a fiddle with my code: http://jsfiddle.net/43qahfsn/2/
Would using percentages instead of pixels make a difference? Or is there some better way to do this?
#box {
width:1200px;
height:700px;
}
.text, .stripe, .photo {
position: absolute;
text-align: center;
}
.text {
color:#000;
top: 50px;
left: 250px;
}
.stripe {
z-index: 1;
top: 0px;
left: 0px;
}
.photo {
top: 400px;
left: 600px;
}
You need to make the positioning of the absolutely positioned elements relative to their parent. In your case wrap them in a div and apply position:relative; to it.
.container {
position:relative;
}
<div class="container">
<!-- your current html --->
</div>
Demo http://jsfiddle.net/43qahfsn/5/

JS/CSS. How do I force a child div to the bottom of it's parent div

I have a parent-child div relationship with the child intended as a horizontal scrollbar attached to the bottom edge of the parent.
The parent is a vertically growable/shrinkable container for rectangular strips that are added/deleted by the user interactively.
How do I force the scrollbar to adhere to the parent's bottom edge?
Here is my current css situation:
.parent-div {
position: absolute;
left: 0;
top:80px;
right: 0;
}
.horizontal-scrollbar-div {
position: absolute;
top: 0;
left: 0;
bottom:-50px;
height:50px;
width: 100%;
z-index: 500;
}
This is not working correctly. At runtime strips get added the scrollbar remains at the top edge of the parent (initially there are no horizontal strips so the parent has 0 height).
What are the css changes I need to make here?
Thanks,
Doug
Marc's answer is right, but in order for it to work you need to add "position: relative;" on the ".parent-div". Otherwise the ".horizontal-scrollbar-div" would position itself according to the body element instead of ".parent-div".
Here is how I would do it. You can change the height of parent and the scrollbar will always stay at bottom of the parent-div.
.parent-div {
position: relative;
height:200px;
background-color:#aaa;
}
.horizontal-scrollbar-div {
position: absolute;
bottom: 0;
height:50px;
width: 100%;
background-color:yellow;
}
<div class="parent-div">
<div class="horizontal-scrollbar-div"></div>
</div>
I would try the following:
.horizontal-scrollbar-div {
position: absolute;
left: 0;
bottom: 0;
height:50px;
width: 100%;
z-index: 500;
}
You want the bottom edge of .horizontal-scrollbar-div to be pinned to the bottom edge
of the parent container.
Note: You may not need the z-index property.
Also: You may need a minimum height to .parent-div.

This layout just seems not to be suited for the usual CSS techniques

Just check this fiddle:
http://jsfiddle.net/9EJpu/25/
How can I stretch the blue div 100% horizontally so it docks to the purple right div?
If I set width:100% its just doing what a div is used for to "line-break" down the purple div.
I also tried display:inline(-block) nothing helped to make the purple div stay on the same
line as the blue div.
The solution must work on IE9. Please no CSS3 hacks.
If I interpret your question correctly you need to change a couple of things...
#wrap {
width:100%;
height:100%;
background-color:green;
position: relative;
}
#left_col {
overflow:auto;
float:left;
height:100%;
margin-right: 100px;
background-color:blue;
}
#right_col {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width:100px;
background-color:purple;
}
You could add position: fixed to #right_col, but it would cover your footer.
Here is a demo:
http://jsfiddle.net/xuBfe/ ​
Using CSS3's relatively safe calc property. -> http://jsfiddle.net/joplomacedo/9EJpu/27/
You can use safer properties though, that just seemed the quickest way to do it with your existing markup.
Example:
http://jsfiddle.net/hunter/9EJpu/37/
To get the content of the main panel to have the proper width you can add a wrapping element within left-col
#left_col
{
overflow:auto;
float:left;
height:100%;
width:100%;
background-color:blue;
}
#left_col > *
{
margin-right: 100px;
}
#right_col
{
right: 0;
top: 0;
position:fixed;
z-index: 1000;
height:100%;
float:right;
width:100px;
background-color:purple;
}
#footer
{
width: 100%;
bottom: 0;
left: 0;
position: fixed;
background-color:yellow;
z-index: 2000;
}
Another possible solution that makes use of the safer box-sizing property.
http://tinkerbin.com/Vi1Rtt1T
make blue width 100% and pad the right side with the width of the purple, purple should have fixed on the right
Edit:
yes I forgot, ok then just float a div to the right side with the width of the purple (inside of the blue). Just need a space holder so things don't run underneathe