CSS: position: fixed shift div - html

I have a custom hellobar in the main template of a website. I would like to move it from the main template to inside a particular page.
This is a hellobar that popup 5 seconds after the page is loaded. Please note that I remove all the javascript part to simplify. If I change hellobar-wrapper to position: absolute or fixed the div is positioned on top of the page but over the header. I would that initially the header is on top and when the hellobar is displayed it shift the header below the bar, so the header is still visible.
HTML:
<!-- Remove hellobar from here -->
<!--<div id="hellobar">Hellobar here</div>-->
<!-- /hellobar -->
<!-- Header -->
<div id="header">
Header here.
</div>
<div id="content">
<!-- hellobar should be here -->
<div class="hellobar-wrapper">
Hellobar content here
</div>
<!-- /hellobar -->
<!-- More content here -->
<div>
more content here
</div>
</div>
</body>
CSS:
.hellobar-wrapper {background-color: #fff; padding: 10px 0px; position: static; top: 0; width: 100%; z-index: 1; border-bottom: 1px solid #eee}

I would suggest to you to add the following to the hellobar-wrapper class in css:
display: none;
Moreover, create in css the following class:
.active {
display: block;
}
Finally, add to your code in Javascript, the following when you load wrapper after five seconds:
$(".hellobar-wrapper").addClass("active");
The code above uses jQuery, therefore add the following in your html code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>
In this way, after five seconds with JavaScript you will display the wrapper correctly, adding the class .active, and you will hide it before the five seconds by default with the css. Please also invert the position of header and wrapper. The wrapper, indeed, will be not visible before the 5 seconds, and the header will be on top. After five seconds, the header will shift since wrapper will be visible

Related

Relative position causing content to come on top of nav-bar

I have a navbar that has its position fixed. If i give the content of the body position relative it is causing that content to move over the navbar, instead of moving underneath the navbar. I tried giving navBar higher z-index values, but that didn't work out. Is there any workaround? (Using transform(translate()) is also causing the content with that style applied to come on top.)
P.S. Giving z-index of -1 to the contents who has either relative positioning or has transform applied can make the content to go beneath. But then, I have to apply that to all the contents of the page. So I would prefer something that can be done easier.
I have added some dummy code to illustrate the issue. I would like the content to go beneath the navbar by changing the css of just the navbar because I have a lot of content in reality and changing all the code would be difficult.
Code to illustrate the issue.
hello my friend i thing this code might be better then yourse check it
<!DOCTYPE html>
<html>
<head>
<title>exircice</title>
<!--styling -->
<style type="text/css">
.navbar
{
background-color: red;
width:100vw;
position: fixed;
left: 0;
right: 0;height:40px;
z-index: 2;
}
.content
{
position: relative;
top: 45px;
height: 1000px;
background: #000;
z-index: 1;
}
</style>
</head>
<body>
<!--navbar -->
<div class="navbar">
<p>text here</p>
</div>
<!--navbar -->
<div class="content"> <!--navbar -->
</div>
</body>
</html>

Polymer app-header not working as intended without app-header-layout

Due to stacking context issues with app-header-layout I had to remove that component completely and use <app-header condenses reveals> by it's own.
My issue is that the header condense, sticky and reveal behaviors are not working as expected and doing weird things.
<!-- <app-header-layout has-scrolling-region> -->
<app-header condenses reveals effects="waterfall">
<div id="pageToolbar">
<!-- Various global stuff, logo, search, social links -->
</div>
<div id="pageHeader" sticky>
<!--
Dynamic content that changes based on the page,
normally contain tabs, and should therefor be sticky
-->
</div>
</app-header>
<div id="content">
<!-- Actual content -->
</div>
<!-- </app-header-layout> -->
Issues
The header scrolls out of view way too fast, leaving a visible gap between it and the content.
Scrolling back up doesn't reveal, until you reach the top; You see the gap again, before the header slides fully into place.
The sticky element doesn't stick.
All of this worked as expected inside app-header-layout.
App Layout version
"app-layout": "PolymerElements/app-layout#^0.10.6",
It's certainly because the <app-header-layout> element was defining some styles that makes the <app-toolbar> work.
Copy the styles defined in the example linked and it should work better.
Don't forget to add :
the is="custom-style" attribute in <style>,
the fixed attribute in <app-header>,
the { padding-top: [your-header-size] } CSS rule to your #content div.
<style is="custom-style">
body {
margin: 0;
}
app-header {
position: fixed;
top: 0; left: 0;
width: 100%;
height: 100px;
color: white;
background: dodgerblue;
}
div#content{
padding-top: 100px;
}
</style>

Positioning issue on different pages

Basically I have a web page which contains a slider, a banner, a menu and content.
My HTML code looks like:
<div class="slideshow">
...
</div>
<div class="banner">
...
</div>
<div class="navigation">
...
</div>
<div class="content">
...
</div>
and CSS
.banner
{
z-index: 1000;
position:absolute;
width: 100%;
top: 0;
margin-bottom: 140px;
}
.navigation
{
margin: 0px auto 0;
}
.content
{
padding: 0px;
margin-bottom: 40px;
}
Slider is displayed only on homepage and everything is OK. But if I open a content page div.slider is not displayed (which I do want this) and div.navigation goes up to page's top and looks under the div.banner since div.banner has z-index and position:absolute (see Actual view 1).
I have tried to add margin-bottom:140px to div.banner but did not work. Then I tried to put margin-top:140px to div.navigation but there is a gap between div.slider and div.navigation in homepage (see Actual view 2).
I want div.slider and div.banner to stick to page's top together but div.slider will be under div.banner. Also when div.slider is not displayed I want div.navigation to be displayed right after div.banner (see Desired view).
You may also want to check fiddle
Your approach is incorrect :
What is expected to be repeated on other pages, keep it relative....DOM which is visible only on 1 page, keep it absolute, this way you'll avoid any headaches as relative is a kind of by-default position!
<div class="slideshow">
<!--
keep it :
position:absolute;
top : 0;
left : 0;
right : 0;
-->
</div>
<div class="banner">
<!--
position : relative
place top left right according to your DOM layout
-->
</div>

Horizontal scrolling site with vertical scrolling elements

I'm trying to create a site very much like in this picture:
Layout Image on Dropbox
The Problem:
I need the site to scroll horizontally, as suggested in the image.
I also need the vertically scrolling elements to scroll, but inside the element itself, not the entire site. When I scroll up/down in the first frame of the site, it scrolls down to a blank area because the second frame is so tall and forces the entire site to be as tall as the tallest element.
HTML structure:
div #horizontal-container
div #horizontal-wrapper
div #section-1 .section
div #section-2 .section
div #section-3 .section
so on...
CSS:
html, body {
overflow: hidden;
}
#horizontal-container {
position: fixed;
top: 0; bottom: 0; left: 0; right: 0;
overflow-y: hidden;
overflow-x: scroll;
}
#horizontal-wrapper {
width: 400%;
height: 100%;
}
.section {
width: 25%; /* A quarter of its parent with 400%, to be 100% of the window. */
height: 100%;
float: left;
overflow-y: scroll;
}
Hopefully I made it clear here. What am I missing to get this working? Should I maybe incorporate a little JavaScript to toggle the overflow property of the container when I hit certain horizontal scroll points? That sounds messy. :/
height=100% will not introduce scroll to sections
You have to assign different heights to sections based on there content.
Check by javascript If height of section is more than window height then assign window height to the section height.
You can try this code to generate fixed width content blocks with horizontal scroller. You can see the parent post here
<html>
<title>HTMLExplorer Demo: Horizontal Scrolling Content</title>
<head>
<style type="text/css">
#outer_wrapper {
overflow: scroll;
width:100%;
}
#outer_wrapper #inner_wrapper {
width:6000px; /* If you have more elements, increase the width accordingly */
}
#outer_wrapper #inner_wrapper div.box { /* Define the properties of inner block */
width: 250px;
height:300px;
float: left;
margin: 0 4px 0 0;
border:1px grey solid;
}
</style>
</head>
<body>
<div id="outer_wrapper">
<div id="inner_wrapper">
<div class="box">
<!-- Add desired content here -->
HTMLExplorer.com - Explores HTML, CSS, Jquery, XML, PHP, JSON, Javascript
</div>
<div class="box">
<!-- Add desired content here -->
HTMLExplorer.com - Explores HTML, CSS, Jquery, XML, PHP, JSON, Javascript
</div>
<div class="box">
<!-- Add desired content here -->
HTMLExplorer.com - Explores HTML, CSS, Jquery, XML, PHP, JSON, Javascript
</div>
<div class="box">
<!-- Add desired content here -->
HTMLExplorer.com - Explores HTML, CSS, Jquery, XML, PHP, JSON, Javascript
</div>
<div class="box">
<!-- Add desired content here -->
HTMLExplorer.com - Explores HTML, CSS, Jquery, XML, PHP, JSON, Javascript
</div>
<div class="box">
<!-- Add desired content here -->
HTMLExplorer.com - Explores HTML, CSS, Jquery, XML, PHP, JSON, Javascript
</div>
<!-- more boxes here -->
</div>
</div>
</body>
</html>

Fading Background

I want to have a panel open up whenever I click a link. I want the entire page to fade out and only have that panel visible.
How can I do that?
Thanks
Kousha
You could set a div with position fixed to the top left corner, height and width 100%, z-indexed higher than everything and CSS transition or jQuery animate the div into view. Use an opaque background so the parent page is not visible.
you have to prepare 2 things:
a div to cover the whole page
the panel you want to fade in
upon clicking the link, "fade in" the div so that it will cover the entire page and fade in the panel as well. You may need to specify the z-index of that div and panel to make sure they are on top.
As far I get it, you can have this effect by two way
1. For first way you need to separate your content and the panel like-
<div id="container">
<div id="content">
<!-- your content goes here -->
link
</div>
<div id="panel">
<!-- your panel code goes here-->
</div>
</div>
and position your panel absolutely respected to the container and use some jQuery to fade the content div out like-
$(document).ready(function(){
$('#link').on('click',function(){
$('#panel').show();
$('#content').hide();
});
});
If you need to keep your panel code beside the links then you can reduce the opacity of the content like-
<div id="container">
<div id="content">
<!-- your content goes here -->
Link
</div>
<div id="panel">
<!-- your panel code goes here-->
</div>
</div>
and the jQuery-
$(document).ready(function(){
$('#link').on('click',function(){
$('#panel').show();
$('#content').css('opacity','0');
});
});
This is a rough code and I've omitted many thing. I hope you'll figure out when you have the idea. Thanks
You can have a div with the contents of the page, and another with the contents of the panel. You will probably want to position your panel at an absolute or fixed position on the page. After that, you can just attach functions in JavaScript/jQuery to whatever events you want to trigger the fade to change the opacity or display of your page contents and panel. Below is an example.
HTML:
<div id="A">
<div id="B">
<p id="1">Click Me!</p>
</div>
</div>
<div id="C"><p id="2">Click Me!</p></div>
CSS:
p {
cursor: pointer;
}
#A {
height: 400px;
width: 300px;
background: grey;
}
#B {
height: 200px;
width: 300px;
background: red;
}
#C {
height: 100px;
width: 200px;
background: blue;
position: absolute;
top: 50px;
left: 50px;
display: none;
}
jQuery:
$('#1').click(function(){
$('#A').fadeOut('slow');
$('#C').fadeIn('slow');
});
$('#2').click(function() {
$('#C').fadeOut('slow');
$('#A').fadeIn('slow');
});
Demo
In this example, the "A" div would be your contents and the "C" div would be your panel. The p texts that say "Click Me!" are your links.