Position absolute div's in a bootstrap col - css

I try to position divs absolute in a bootstrap col-
red{
background-color:red;
}
.grid-item{
position:relative;
}
.about{
position:absolute;
left:20px;
top:20px;
}
.app{
position:absolute;
right:10px;
top:10px;
}
Here is my fiddle:
http://jsfiddle.net/nilssi/ah7m2k01/5/
The positions a good, but i would aspect a red background.

Try giving height and width to .red you can see that red color gets applied:
.red{
background-color:red;
height:200px;
width:200px;
}
DEMO

Related

Fitting content to window height

I have this css:
html,body {margin:0;}
#nav {
height:30px;
background:#FFF;
background:red;
}
#content {
position:absolute;
left:0;
bottom:0;
top:30px;
right:0;
height:100%;
background:green;
}
I'm trying to have a nav bar at the top (the red part) and the content area underneath (the green part) should just fill the remaining space but as you can see the height is more than the window height creating a scroll. How can I overcome this?
jsFiddle: http://jsfiddle.net/2dcr5yty/5/
Don't use a height 100%. Use a bottom: 0. Because it will be 100% height of the container. Which is the body, so 100% body height means. covering the whole document if position top = 0. Since you have it 30px top. It will have a scrollbar for 30px.
Example: http://jsfiddle.net/2dcr5yty/6/
#content {
position:absolute;
left:0;
bottom:0;
top:30px;
right:0;
bottom:0;
background:green;
}

z-index not working on span with :before

How to put the :before behind the span? I know I did this before but I can't remember how.
Here's the fiddle.
HTML
<span>Stack Overflow</span>
CSS
span{
background:#000;
position:relative;
color:#fff;
z-index:20;
}
span:before{
content:'';
background:#000;
position:absolute;
left:50%;
bottom:-10px;
width:20px;
height:20px;
z-index:1;
}
Fiddle
z-index is relative, so for the :before pseudo-element to appear underneath its parent <span>, you can specify a z-index of -1:
span:before{
content:'';
background:#000;
position:absolute;
left:50%;
bottom:-10px;
width:20px;
height:20px;
z-index:-1;
}
jsFiddle Demo

z index and position relative

w3c Says that z-index "Only works on positioned elements(position: absolute;, position: relative; or position: fixed;)."
I see it works in absolute position: http://jsfiddle.net/WwXVV/2/
But why not in relative position: http://jsfiddle.net/WwXVV/
Can anyone explain why in relative position and in this specific case the div with the higher z-index is not on top?
CSS:
#top {
position:relative;
float:left;
width:100px; height:100px;
background-color:yellow;
z-index:1;
}
#bottom {
position:relative;
float:left;
width:100px; height:100px;
background-color:blue;
z-index:0;
}
HTML:
<div id="top"></div>
<div id="bottom"></div>
You are simply floating them next to one another. Apply left to the bottom div:
#bottom { left: -100px; }
What this will do is "position" the bottom div under the top one. Applying relative position by itself won't do anything, you need to start moving the target element around to see the stacking effect.
If you are wondering about absolute positioning, it works differently. Absolute positioning takes the element out of document flow (meaning it won't affect the layout of other elements), and by default puts it at the top left of its first ancestor that doesn't have a value of position:static, so both your elements stacked on top of each other.
You have floated both elements to the left. They don't overlap, hence z-index doesn't do anything.
If you add margin-left: -20px to the right box, you'll see the desired effect.
Simple, with position:relative and float:left; the divs will be next to each other. With position: absolute they will ignore float:left; and will put both element on the same spot, using z-index to show who is in front.
z-index is just relevant when the boxes overlap visually.
In case of Relative Positioning, z-index working fine. Try this code
#top {
position:relative;
top:20px;
left:0px;
width:100px; height:100px;
background-color:yellow;
z-index:1;
}
#bottom {
position:relative;
top:0px;
left:30px;
width:100px; height:100px;
background-color:blue;
z-index:0;
}
In case of Absolute Positioning
#top {
position:absolute;
top:0px;
left:20px;
top:0; left:0;
width:100px; height:100px;
background-color:yellow;
z-index:1;
}
#bottom {
position:absolute;
top:20px; left:50px;
width:100px; height:100px;
background-color:blue;
z-index:0;
}

CSS Layout - Avoid vertical scroll bar

I'm trying to create a HTML CSS Layout using div tag.
Code here
Now it display a vertical bar. I want to avoid this vertical bar, and would like to display only if the content is big.
May you wnt an Sticky Footer than put your footer outside the #container.
Check this http://jsbin.com/ujemaq/17
EDIT:
Ok your actual problem arises with the height ambiguity, see these line:
#container{
min-height: 100%;
width:100%;
height:100%; /* this causes container to a 100% height of body*/
}
#header{
width:100%;
height:55px; /* this takes 55px of container height*/
/*border:2px solid;*/
}
#menu{
width:100%;
height:20px; /* this takes another 20px of container height*/
/*border:2px solid;*/
}
#left-nav{
width:20%;
height:100%;
float:left;
/*border:2px solid;*/
}
#content{
height:100%; /*You thinking of getting full height of container but the 75px height is already grabbed by header and menu, so while expanding content to 100% height a vertical scrollbar appears */
/*border:2px solid;*/
}
apply this css
body,html{
height:100%;
}
#container{
min-height: 100%;
width:100%;
height:100%;
}
#header{
width:100%;
height:55px;
/*border:2px solid;*/
}
#menu{
width:100%;
height:20px;
/*border:2px solid;*/
}
#left-nav{
width:20%;
float:left;
/*border:2px solid;*/
}
#content{
height:85%;
/*border:2px solid;*/
}
#footer{
background-color:#FFA500;text-align:center;
}
</style>

z-index is not respected

I have this styles:
header{
width:400px;
min-height:640px;
background:#9B9B76;
float:left;
z-index:1000; /*high*/
}
nav{
width:100%;
z-index:1001; /*highest*/
}
nav a{
float:left;
width:80%;
padding:10%;
font-size:20px;
}
nav a:hover{
background:#997548;
}
.LevelCnt_1{
float:left;
width:300px;
z-index:1; /*Lowest*/
position:absolute;
left:400px;
background:#baafa9;
}
the problem is that visually .LevelCnt_1 stays on top of header if I set left:0px
why is this happening?
z-index only work with position relative, absolute & fixed. So, give position:relative to your header & nav DIV .
Like this
header{
width:400px;
min-height:640px;
background:#9B9B76;
float:left;
z-index:1000; /*high*/
position:relative
}
nav{
width:100%;
z-index:1001; /*highest*/
position:relative
}

Resources