Z-index not working - javascript

Take a look at this page I'm working on: http://s361608839.websitehome.co.uk/textcube/
The nav bar is going behind the slider and I wanted it to sit above instead. I've tried setting a high z-index on the #navbar and #navbar-inner and nothing happened.
#navbar{
background: url(../images/nav-bg.png) repeat-x;
height: 55px;
margin: 0;
padding: 0;
z-index: 9999;
}
#navbar-inner{
width: 912px;
margin: 0 auto;
position: relative;
z-index: 9999;
}
I think the javascript slider using CSS style .bx-window and .bx-window are the cause however I have set a low z-index on both, yet I don't see any difference.
Help with this would definately be appeciated.
Cheers

z-index works only with positioned elements (position:absolute, position:relative).
Here's an article http://www.w3.org/TR/CSS2/visuren.html#z-index
In your case, you forgot to add position to one of your element.

Add position:relative to #navbar

It works with either float:... or position:...

Related

Bootstrap4 Navbar doesn't work with "jQuery.BgSwitcher" in mobile

So I am using Bootstrap4 (Bootswatch4 to be more specific) and I need a div with changing/fading backgrounds. I found that js to be closest to what I want: https://github.com/rewish/jquery-bgswitcher
So I use it like this in https://jsfiddle.net/p5d8rskg/:
$(".banana").bgswitcher({
images: ["image1.jpg", "image2.jpg"],
interval: 5000,
duration: 2000
});
Everything works fine in the desktop version. But the problem is that in mobile version the navbar goes over the div and pushes the content of the div outside. How can I fix this "bug"? Or are there simpler approaches to get the same effect as with "bgswitcher" without that "bug"?
Thanks for your input.
More a hacky solution, but a workable one is to use position: absolute for your .banana container. This way the container is fixed to your defined position.
I have updated your fiddle in order to show the solution:
nav {
z-index: 1000 !important;
}
.banana {
background-color: powderblue;
height: 400px;
width: 400px;
background-size: cover;
color: white;
font-size: 30px;
position: absolute;
top: 56px;
left: 0;
}
Basically i added position: absolute as well as top: 56px (the height of your navbar) and left: 0 to define the position. In order to bring your navbar to the front and not the text apply a bigger z-index to this element.
Good luck!

Display div over everything

I'm struggling to display a div on top of everything else.
I've followed other post on SO which say to use z-index and position: absolute.
Here is a screenshot to describe what I mean.
Here are the css attributes on the classes:
#media only screen and (min-width: 600px) {
.cd-single-point .cd-more-info {
position: absolute;
width: 200px;
height: 240px;
padding: 1em;
overflow-y: visible;
z-index: 10;
line-height: 1.4;
border-radius: 0.25em;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}
}
If anyone is able to help me I'd really appreciate it.
The link can be found here https://what-is-wrong-with-this-css.herokuapp.com/.
Thanks
You have issue with overflow in the class .cd-image-wrapper, you need to make it visible like this :
.cd-image-wrapper {
position: relative;
overflow: visible;
z-index: 2;
}
Can you try and increase the z-index: 999;
Try to increase the z-index to 9999
Try to use !important (maybe something is overriding it)
Try to decrease the z-index of the overlaping element (again try with !important)
Try to change something obvious in your media query to make sure that it is currently executed, for example change the background color
Note: this is just to experiment and find the cause of your issue, using "!important" is not recommended

Sticking side menu to top

I've been looking into sticking a "div" to the top of the screen when you scroll past it, or making the div scroll with the page when it reaches the top of the screen.
The issue i get when i try this matter is that changing to position: fixed; using either jquery or the simple css, removes the float from the element.
My layout look somewhat like this: http://jsfiddle.net/ThSXm/33/ <-- updated
So when the float is removed, the id="content" get's overlapped by the sidemenu, making the sidemenu bigger and out of place.
I need a solution where you dont have to alter the position of the elements or if there is some fix i can make on the content div so it wont get overlapped when changing the positions.
Update
Sandeeproop managed to help me with the positioning, but the scroll matter is still a issue.
As i mentioned in the comment for this question, the div has to scroll/stick to the top of the screen when the div is close to the top or reaches the top (and preferably stop once the div reaches the footer or is close to reaching the footer), because there are more divs (header/slideshow etc) before we reach the side menu, and you wont see the menu if you just use position: fixed.
Any thoughts?
/update
Looking forward to some answers!
//Jim
If i understand you question correctly.
Please check this fiddle.
#nav {
width: 136px;
position: fixed;
background: #FF0000;
margin-left: 1em;
margin-top: 1em;
}
#content{
width: 80%;
height: 600px;
background: #FF9966;
float: left;
margin-left: 170px;
margin-top: 1em;
}
You can set fixed margin-top values for nav and content elements.
Something like that http://jsfiddle.net/ThSXm/26/
#nav {
width: 15%;
height: 100%;
float: left;
background: #FF0000;
margin-left: 1em;
margin-top: 60px;
}
#content{
width: 80%;
height: 600px;
background: #FF9966;
float: left;
margin-left: 1em;
margin-top: 60px;
}
I guess what you are looking for is "position: sticky".
This is not yet supported by many browsers, but here is a pollyfill for it
http://philipwalton.github.io/polyfill/demos/position-sticky/
Have you considered a solution where you use position:absolute on the element?
Have it being absolute untill you need it to stick and then change it to fixed.
Here is a simple fiddle:
http://jsfiddle.net/dXe97/
if ($(this).scrollTop() > boxTop) {
$box.css({
'position':'fixed',
'top': 0
});
}else{
$box.css({
'position':'absolute',
'top': 150
});
};
The .box element is absolute positioned, but when you scroll down passed the element, it is changed to fixed and its top value is set to 0, and back again when you scroll up.

avoid unwanted scaling for image in parallax scrolling effect

here is my demo, as you can see the image scale so the margin:top of the parallax wrapper can't be dynamic.
demo : http://jsfiddle.net/KsdeX/12/
.wrapper-parallax {
margin-top: 150px;
margin-bottom: 60px;
}
what are the possible solution for this? max width for the img?
yes, i dont really understand whats the problem here, you can just do
img {
position: fixed;
top: 0;
max-width: 350px;
z-index: -1;
background: cyan;
}
and then the image wont scale anymore.. ?
I believe this is what you wanted..
I had to use some javascript in this code, and declared some ids to make it easy for me :p
fiddle

Floating menu bar using HTML/CSS?

wondered if any one knew of a way of creating a floating menu bar that sticks to a point on a page until the browser window gets far enough down the page and unsticks it and then the menu bar begins to scroll along with it. The effect I want is the exact same as this http://www.jtricks.com/javascript/navigation/floating.html javascript menu. However, I really want to do this with CSS. I am aware I can make the div Absolutely positioned and it will move down the page, I tried making one DIV relative positioned (parent div) and then another div inside this which was absolute positioned, but I could not get this to work. Does any one know how to make this work with CSS or does it need to be JS?
Thanks in advance.
Jon.
I believe using javascript is the only solution to get the effect you described. Here's a quick demo of a banner that starts in a absolute position and goes to fixed when the user scrolls.
<div style="height:1000px;width:500px;">
<div id="floatbar" style="background:gray;
width:200px;
height:40px;
position:absolute;
left:0;top:200px;">
</div>
</div>
$(window).scroll(function(){
if ($(window).scrollTop() >= 200)
{
$("#floatbar").css({position:'fixed',left:'0',top:'0'});
}
else
{
$("#floatbar").css({position:'absolute',left:'0',top:'200px'});
}
});
well if you do NOT need the animation, than just use
position: fixed;
in the css.
if you want it animated you need to use javascript.
for example in jquery:
$(window).scroll(function(){
$('#menu').css({
right: 0,
top: 0
})
})
Well you can't do it with absolute positioned div inside of a relative. Fixed position is basically an absolute positioned div, positioned relatively to the window. I'd say you definately need javascript here.
This should be rather easy with a fixed sidebar, and a floating content section. Try something like this...
#container {
width: 960px;
margin: 0 auto;
overflow: hidden;
position: relative;
}
#sidenav {
width: 300px;
position: fixed; /*--Fix the sidenav to stay in one spot--*/
float: left; /*--Keeps sidenav into place when Fixed positioning fails--*/
}
#content {
float: right; /*--Keeps content to the right side--*/
width: 620px;
padding: 0 20px 20px;
}
This is old post but CSS has changed a lot since then, we can do a floating menu with plain CSS. See sample code below. Credit to https://www.quackit.com/css/codes/css_floating_menu.cfm
main {
margin-bottom: 200%;
}
.floating-menu {
font-family: sans-serif;
background: yellowgreen;
padding: 5px;;
width: 130px;
z-index: 100;
position: fixed;
right: 0px;/* You can change float left/right */
}
.floating-menu a,
.floating-menu h3 {
font-size: 0.9em;
display: block;
margin: 0 0.5em;
color: white;
}
<!DOCTYPE html>
<title>Example</title>
<main>
<p>Scroll down and watch the menu remain fixed in the same position, as though it was floating.</p>
<nav class="floating-menu">
<h3>Floating Menu</h3>
CSS
HTML
Database
</nav>
</main>
I believe it needs to be JS. I can imagine it can be rather simple with jQuery and I really cannot think of any way to achieve this only with CSS. I'll try to think about it, but I doubt I'll find a solution.

Categories

Resources