Horizontal scrolling of sticky header doesn't working - html

I have a sticky header on my page, but I found a bug that buttons on right side of sticky header is not visible when browser window is small... and horizontal scrolling does not work for hearder.
Here is html code:
<div class="search-container">
<div class="sticky-wrapper">
<!-- it's fixed header -->
</div>
<div class="sidebar">
<!-- search filters e.g. -->
</div>
<div class="content">
<!-- search results e.g. -->
</div>
</div>
Here is my CSS (sass) code:
.search-container {
.sticky-wrapper {
box-shadow: 0 3px 3px 0 #8f8f8f;
position: fixed;
top: 0;
z-index: 999;
}
.sidebar {
float: left;
margin-left: 5px;
width: 229px;
}
.content {
background: none repeat scroll 0 0 #fff;
border-top: 4px solid #5d5d5d;
display: inline;
float: left;
margin-left: 18px;
margin-right: 0;
width: 691px !important;
}
}
When I make browser window smaller then (sidebar + content) width, horizontal scrolling appears - but it works only for .sidebar and .content.
How can I make sticky header horizontal-scrollable too?
P.S. it's important to working in FF, Chrome, IE >= 9. And I it not good to change/add new css ids or classes, cause many tests become broken.
Please, help.
Thanks kindly.
If it will be helpful - jsfiddle with header and content

I think CSS alone cannot handle this scenario. It would be better if you add a pinch of JS flavour. Try this Fiddle.
Added a JS code: (Note: I have used JQuery, you can also have it rewritten in pure JS if required)
$(window).scroll(function() {
var max_width = 990;
if ($(window).width() < max_width) {
$('.sticky-wrapper').css('margin-left', -$(this).scrollLeft() + "px");
}
});

For what I could test, and for previous experience, is to add a div inside with a width bigger than the container one, and to that container add an overflow-x: auto;
For example:
<div class="sticky-wrapper">
<div class="bigger">Your text here</div>
</div>
.sticky-wrapper {
box-shadow: 0 3px 3px 0 #8f8f8f;
position: fixed;
top: 0;
z-index: 999;
background: grey;
width: 900px;
overflow-x: auto;
}
.bigger {
width: 1000px;
}
Fiddle: https://jsfiddle.net/afs5k1zp/1/

Related

How to add shadow 'wings' to a centered content div

I've got a stylized page that I've been using to practice JavaScript in but recently I found out that some of my CSS was blocking my document listener from hearing mouse clicks targeted at embedded elements beyond the target of the culprit CSS.
Culprit CSS
.backDrop {
background-color: #FFF;
height: 100vh; width: 720px;
margin: auto;
/*box-shadow: creates ill-desired corners;*/
}
.backDrop:before {
box-shadow: 0 0 20px -20px black;/* shrinks and blurs for a soft shadow*/
content:'';
height: 200vh;
position: absolute; /* <-- THIS [but there's no shadow without it]*/
width: 720px;
}
So to circumvent this problem I implemented a parent div classed wrapper and embedded backDrop along with two sister divs classed backDrop_leftShadow and backDrop_rightShadow to each side of it. Then I created two alternatively oriented background images of a horizontal gradient that fades from black to transparent, and assigned them to the CSS for my 'wing' divs.
Each div follows a normal indentation scheme, but I've had to separate them from each other with <!--comment-->s to prevent white space from mucking up the rendered layout. From there I moved the viewWidth and margin CSS from backDrop to wrapper and replaced the viewWidth units in backDrop with percentage and pixel units. The gradients I made are 7 pixels wide, so I made wrapper 14 pixels wider than backDrop and each wing div 7 pixels wide. Then I tried every combination of display: inline-block, inline, block; I could think of in the CSS for each sister div inside wrapper --but nothing seems to work.
var element = document.getElementById("addItem");
element.addEventListener('click', promptFunction);
function promptFunction() {
element.innerHTML = square(window.prompt('inputvar'));
}
function square(x) {
return x * x;
}
body {
background-color: #3A3C3D; /*alt color #CCA #3A3C3D*/
margin: 0;
overflow: hidden; /*top stop the extended shadow element height from causing the page to scroll*/
}
.backDrop {
background-color: #FFF; /*alt colors #ACA null #CCA*/
display: inline-block;
height: 100%; width: 720px;
}
.backDrop_leftShadow {
background-image: url("http://s14.postimg.org/7p3o980el/left_shadow.png");
background-repeat: repeat-y;
display: inline-block;
height: 100%;
width: 7px;
}
.backDrop_rightShadow {
background-image: url("http://s14.postimg.org/cc9qaznrh/right_shadow.png");
background-repeat: repeat-y;
display: inline-block;
height: 100%;
width: 7px;
}
.wrapper {
background-color: red;
width: 734px;
margin: auto;
}
.interface {
background-color: rgba(255, 0 , 0, 0);
background-image: url("../code/assets/experimenting pot/img/isometric platforms.png");
border-left: 2px solid red;
border-radius: 5px;
box-shadow: 0 0 5px -2px rgba(0,0,0,.4);
margin: auto;
height: 270px; width: 480px;
}
.lineBreak {
height: 16px;
}
<body><!--All the comments you'll see below are meant to null white space between layout elements--><!--
--><div class="wrapper"><!--
--><div class="backDrop_leftShadow"></div><!--
--><div class="backDrop" id="backDrop"><!--
--><div class="lineBreak" id="addItem">click here to square</div><!--
--><div class="lineBreak"></div><!--
--><div class="interface">yo</div>
</div><!--
--><div class="backDrop_rightShadow"></div></div>
<!--<script language="javascript" type="text/javascript" src="../javascript/viewportControl.js"></script>-->
</body>
Note: I attempted to upload my gradients to an image hosting site so they could be loaded from here, but I can't seem to get that to work right either. I'll be happy to fix that problem if someone knows how. --But more interestingly, the exact code is producing two different renders depending on nothing more than whether it's being rendered locally or through stackoverflow. When this is what I'm going for. Or more accurately, and as I've already said, this. --the 'STACKOVERFLOW' and 'LOCAL' text was edited in with an image editor.
The issue with the first solution that you tried was related to the positioning of the pseudo-element. As it had position:absolute it went on top of the other elements and that caused the issue.
You could easily solve that by also using z-index: if you set the value of z-index to -1, that element will go to the bottom of the stack and won't affect with the event listeners.
Here is a demo of that using your code:
var element = document.getElementById("addItem");
element.addEventListener('click', promptFunction);
function promptFunction() {
element.innerHTML = square(window.prompt('inputvar'));
}
function square(x) {
return x * x;
}
body {
background-color: #3A3C3D; /*alt color #CCA #3A3C3D*/
margin: 0;
overflow: hidden; /*top stop the extended shadow element height from causing the page to scroll*/
}
.backDrop {
background-color: #FFF;
height: 100vh; width: 720px;
margin: auto;
/*box-shadow: creates ill-desired corners;*/
}
.backDrop:before {
box-shadow: 0 0 20px black;/* shrinks and blurs for a soft shadow*/
content:'';
height: 200vh;
position: absolute; /* <-- THIS [but there's no shadow without it]*/
width: 720px;
z-index:-1;
margin-top:-20px; /* to avoid the issue with the borders that you commented */
}
.wrapper {
width: 734px;
margin: auto;
}
.interface {
background-color: rgba(255, 0 , 0, 0);
background-image: url("../code/assets/experimenting pot/img/isometric platforms.png");
border-left: 2px solid red;
border-radius: 5px;
box-shadow: 0 0 5px -2px rgba(0,0,0,.4);
margin: auto;
height: 270px; width: 480px;
}
.lineBreak {
height: 16px;
}
<body><!--All the comments you'll see below are meant to null white space between layout elements--><!--
--><div class="wrapper"><!--
--><div class="backDrop" id="backDrop"><!--
--><div class="lineBreak" id="addItem">click here to square</div><!--
--><div class="lineBreak"></div><!--
--><div class="interface">yo</div>
</div></div>
<!--<script language="javascript" type="text/javascript" src="../javascript/viewportControl.js"></script>-->
</body>
The second part is related to using percentages as values for heights. The heights of the parents need to be set or otherwise the percentage will fail (because 100% of 0 is 0).

How to make content div full height when using padding on wrapper?

I know similar questions have been asked numerous times, but I've tried a number of answers and none seem to work for my situation. I've found a lot of solutions for sticky footers, but that's not exactly what I'm looking for, or maybe I haven't figured out how to use correctly for my situation:
I have fully fixed position navigation (header/sidebars/footer). The content flows on top of the header and footer.
My content wrapper layer is currently a 100% width/ 100% min-height
layer above the navigation layer, and using simple padding on top/bottom and margins on left/right, I'm able to show the navigation elements.
Inside the wrapper layer I have my content div, which has my page
background and a box-shadow. But I can't get the content div to
expand to the full height of the wrapper, because the wrapper height
is based on percentage. So everything works perfectly when I have
content that fills or overflows the window, but when I don't, the content div is too small.
Sticky footer doesn't work in this situation because the sticky footer just covers the content (the content itself is still 100% height). I basically want the content to be min-height 100% - minus the 50px header and 50px footer.
Is there any css solution to this without using a javascript hack or calc()?
I would be willing to have the header + footer not be fix positioned - but I want to keep the box-shadow on the content div (i.e. 50px from top and bottom of the page).
JSFiddle:
https://jsfiddle.net/tyhenry/n9rpbj3m/5/
HTML:
<div id="nav">
<div id="header">
header
</div>
<div id="left-side">
left sidebar
</div>
<div id="right-side">
right sidebar
</div>
<div id="footer">
footer
</div>
</div>
<div id="page-layer">
<div class="page">
content<br>
content<br>
content<br>
</div>
</div>
CSS:
* {
box-sizing: border-box;
}
html, body{
background-color: #eeffff;
text-align: center;
margin: 0;
padding: 0;
height: 100%;
}
#header {
position: fixed;
top:0;
left:0;
width: 100%;
height: 50px;
background-color: #ddd;
}
#left-side {
background-color: #bbb;
position: fixed;
left: 0;
top: 50px;
width: 50px;
height: 100%;
}
#right-side {
background-color: #bbb;
position: fixed;
right: 0;
top: 50px;
width: 50px;
height: 100%;
overflow: hidden;
}
#footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 50px;
background-color: #aaa;
}
#page-layer{
position:relative;
padding: 50px 0 50px 0;
margin: 0 50px 0 50px;
min-height: 100%;
}
.page {
background-color: #fff;
box-shadow: 0px 1px 20px 0px rgba(0, 0, 0, 0.8);
width:100%;
}
If you change the display property to flex it fills the whole (height between header and footer) and adjusts when you resize.
#page-layout {
display: flex;
}
give this you the desirable outcome ? can i use viewport units
add:
.page {
min-height: 100vh; /*min-height not height :)*/
}
Try this updated fiddle https://jsfiddle.net/n9rpbj3m/6/
#page-layer{
position:absolute;
top:50px;
left:50px;
right:50px;
bottom:50px;
}
.page {
position:relative;
background-color: #fff;
box-shadow: 0px 1px 20px 0px rgba(0, 0, 0, 0.8);
height:auto;
min-height: 100%;
width:100%;
}

How to center align/center parallax scrolling content?

I am using a simple parallax scrolling effect however I am running into two problems.
I cannot have the #background stay centered while zooming in and out. If i change the position to relative it will, but it needs to remain fixed to create the parallax effect.
the #nav container is sitting above the background and if i completely remove the #nav container the background will drop to the bottom of the page. I would like the #nav bar to sit on top of the background ultimately creating the same idea in this website: http://www.falve.co.nz/collection/
Below is my code
<div id="page-wrap">
<div id="background"><img src="../images/COVER PHOTO.JPG" width="97%" height="97%"></div>
<nav id="nav">Nav</nav>
<div id="main">"MAIN BODY</div>
CSS
#page-wrap{
position: relative;
min-width: 1366px;
max-width: 2048px;
margin: 0px auto;
width: 100%;
}
#nav {
margin: 0;
height: 0px;
background: #fff;
position: relative;
}
#main {
margin: 1000px 0 0 0;
height: 1200px;
background: #fff;
position: relative;
}
#background {
position: fixed;
margin: auto;
left: 50px;
width: 98%;
height: 97%;
}
JS
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.stellar.min.js"></script>
<script>$(function() {
$(window).on('scroll', function() {
$('#background').css('margin-top', $(window).scrollTop() * -.3);
});
});
</script>
Option #1 (related to your code):
There are some basics missing. For example closing div of page-wrap.
Basically you can set a background for your header and play with it.
With little conditions you can do the same trick with the nav
if ($(this).scrollTop() > 200) {
$("#nav").fadeOut();
} else {
$("#nav").stop().fadeIn();
}
See your Example
Option #2 (Recommended):
I would recommend using a special plugin (skrollr) for parallax related stuff. You can do a lot more with lot more options with individual support.
There is a tutorial section as well.
I hope I helped you with my first answer here.

How can I push an image that is floated right to the bottom of the browser window?

I have an image in my website that is defined with the following CSS:
#settings_big{
border: none !important;
margin: auto 0 0 0 !important;
padding: 0 !important;
float: right;
}
Because of the float the image obviously sits on the right side of the content. The top margin causes the image to sit right beneath the lowest hanging element in the content. This looks OK, but I would really prefer that the image sit as low as possible in the browser window to somewhat frame the content. I've seen multiple examples that use fixed positioning to achieve this, and this would work, however my content has a max and min width of 960px; using a fixed position of
bottom: 0;
right: 0;
causes the image to get pushed far right outside of the content to the edge of the browser window. Is it possible to push the image to the bottom of the browser window while keeping the
float: right;
positioning? I would rather not use JavaScript or jQuery but it is an option I suppose. Thanks in advance.
New answer:
<div class="container contentCont">
<div id="content"></div>
</div>
<div class="container imageCont">
<div id="image"></div>
</div>
With CSS:
.container {
width: 200px;
margin: 0 auto;
background: #ccc;
}
.contentCont {
min-height: 600px;
}
.imageCont {
position: fixed;
bottom: 0;
right: 0;
left: 0;
}
#image {
float: right;
width: 20px;
height: 20px;
border: 4px solid red;
}
Does it right as in this JSFiddle: http://jsfiddle.net/WYX7H/1/
The following might be close to what you need.
Assuming that your page layout vaguely looks like the following HTML:
<div class="wrapper">
<p>some words...</p>
<div class="slot">
<img src="http://placehold.it/200x200">
</div>
</div>
apply the following CSS:
.wrapper {
width: 600px;
height: 600px; /* for demo only, not critical... */
margin: 0 auto;
border: 1px solid blue;
}
.slot {
text-align: right;
position: fixed;
left: 50%;
bottom: 0;
margin-left: -301px;
width: 600px;
border: 1px dotted blue;
}
.wrapper img {
vertical-align: top;
}
See demo at: http://jsfiddle.net/audetwebdesign/6Xnxj/
If you don't know the width of the image (or you don't want to specify it),
create a wrapper that matches the width of the parent element and apply position: fixed to it.
The image can then be either floated or text-aligned to the right within the fixed block.
The fixed block can then be positioned to the left and bottom, and using margin-left
to keep it centered.

Create static toolbar on webpage that follows scroll in HTML

How do you make a toolbar like object in HTML that follows the user's scroll so that it is always at the top of the viewable page?
Thanks in advance!
css
.selector
{
position: fixed;
top: 0;
left: 0;
width: 100%;
}
html
<div class="selector">
... content for bar here ...
</div>
Do you specifically need it to scroll (animate) or just a static (toolbar like) object?
EDIT:
Ok so to add a static(toolbar like) object that has a width which is 100% of the page, and a height of say 25px, you would do this.
HTML
<div id="toolbar">
<p>Some content...</p>
</div>
CSS
#toolbar {
position: fixed;
width: 100%;
height: 25px;
top: 0;
left: 0;
padding: 5px 10px; /* some styling, please note overall height of the object will be 35px due to 5px padding on top/bottom. */
background: #ccc; /* some styling */
border-bottom: 1px solid #333; /* some styling */
}
Please note that this might overlap any content that you have at the top of the page, so use a top margin to push it down under the toolbar or simply set:
body {
margin-top: 35px;
}