Website Design - Scrolling menu that fixes at the top and expands - html

I have a menu that will be run through a javascript and cause the menu to scroll to the top, lock in place, then expand a few pixels.
A live example would be something like this: http://www.kriesi.at/
Currently I have this:
http://jsfiddle.net/djtiii/7cauw/
HTML
<div class="space">
<p></p>
</div>
<div id="menu">
<div class="container">
<div class="pages">
<ul>
<li>Hi,</li>
<li>how</li>
<li>are</li>
<li>you?</li>
</ul>
</div>
<div class="icons">
<img src="http://thegraphicsfairy.com/wp-content/uploads/2014/01/Valentine-Fairy-Image-GraphicsFairy.jpg">
<img src="http://thegraphicsfairy.com/wp-content/uploads/2014/01/Valentine-Fairy-Image-GraphicsFairy.jpg">
</div>
</div>
</div>
CSS
body {
height: 600px;
min-width: 400px;
}
ul {
list-style-type: none;
padding: 0;
margin: 0 auto;
}
.container {
min-width: 380px;
max-width: 380px;
padding: 0;
margin: 0 auto;
}
.space {
height: 100px;
}
#menu {
min-width: 400px;
left: 0;
right: 0;
height: 60px;
border-top: 1px solid black;
border-bottom: 1px solid black;
position: absolute;
margin: 2px 0 0 0;
}
.pages {
height: 60px;
float: left;
border-right: 1px solid black;
border-left: 1px solid black;
}
.icons {
height: 60px;
min-width: 100px;
float: right;
border-left: 1px solid black;
border-right: 1px solid black;
}
.pages li {
line-height: 60px;
display: inline-block;
margin: 0 5px 0 0;
}
.icons img {
float: right;
height: 100%;
width: auto;
}
#menu.fixed {
position: fixed;
top: 0;
z-index: 999;
margin: 0 auto;
}
JavaScript
$(document).ready(function () {
var showStaticMenuBar = false;
$(window).scroll(function () {
if (showStaticMenuBar == false) {
if ($(window).scrollTop() >= 110) {
$('#menu').addClass('fixed');
showStaticMenuBar = true;
}
} else {
if ($(window).scrollTop() < 110) {
$('#menu').removeClass('fixed');
showStaticMenuBar = false;
}
}
});
})
The scroll effect "works", but is slightly broken since the content is fixed width. If the resolution is less than that width, then when the menu fixes to the top it cuts off information to the right. Are there any work around to force a position:fixed into a relative space?
Any stabs at this will be greatly appreciated. Thanks!

Not sure exactly what you are after here, but it looks like you need to look further into responsive web design.
A few css tricks here that may (or may not) help....
If instead of using a min-width and max-width, you set a width and a max-width of 100%, ie
.container {
width:380px;
max-width: 100%;
}
then the width will be 380px, but will then become 100% when the window is less than 380 pixels wide. At the moment, your container is always 380px (no point setting a min-width and max-width if they have the same value, just use width). This is why when the window resolution is smaller than 380px, it cuts off to the right.
To specify styles to use only when the window is below 380px (or any other resolution), you can use the code similar to the following.
#media screen and (max-width:380px) {
.container {
/* NEW STYLES HERE */
}
}
This means that you do not need to write a single style that works for all resolutions - you can tweak it for different resolutions. These are called breakpoints.
If you are using background images, you can scale these using the background-size css property, which allows them to be resized on different resolutions.

Change #menu.fixed to this left:0;right:0;top:0;z-index: 999;margin:auto;position:fixed;

Related

How do prevent my div from spilling outside its parent container?

Here is my code taken from the codepen: http://codepen.io/rags4developer/pen/ONoBpm
Please help me to fix these problems.
How do I prevent the the main div & footer from spilling out of the container div ? overflow: hidden for container will not always work !
How do I make the container div height equal to page height without setting its height to a fixed percentage ?
HTML:
<body>
<div id="container">
<div id="nav">nav links 1,2,3 etc</div>
<div id="main">
<!--no text here-->
<div id="left">left panel</div>
<div id="right">right panel</div>
</div>
<div id="footer">footer</div>
</div>
</body>
CSS:
* {box-sizing: border-box;}
html {height: 100%;}
body {height: 100%;}
#container {
border: 8px solid yellow;
height: 100%;
width: 80%;
margin: 0 auto;
}
#nav {
border: 4px solid red;
height: 15%;
}
#main {
border: 4px solid black;
height: 100%;
background: gray;
}
#left {
border-top: 4px solid green;
border-left: 4px solid green;
border-bottom: 4px solid green;
float: left;
width: 15%;
height:100%;
/*I will make this gradient later*/
background: #9e9999;
}
#right {
border: 4px solid blue;
float: right;
width: 85%;
height: 100%;
border-radius: 20px 0 0 0;
background: white;
}
#footer {
border: 4px solid pink;
clear: both;
}
I am not completely sure if I understand you correctly, but your heights (i.e. the heights within the #container div) add up to 15% + 100% + the height of the footer = at least 115% of the #container height plus the footer height, which causes the "spilling over".
I changed the #content height to 80% and added height: 5%; to the footer in this fork of your codepen: http://codepen.io/anon/pen/EKeOdm
Now everything remains within the #container. Is this what you want?
The clearfix solution still works well for floated elements, IMO. Try removing the height styles and add this:
#main:before,
#main:after {
display: table;
content: "";
}
#main:after {
clear: both;
}
Further: http://nicolasgallagher.com/micro-clearfix-hack/
Using display table should fix this.
#container {
border: 8px solid yellow;
height: 100%;
width: 80%;
margin: 0 auto;
**display: table;**
}
#content {
border: 4px solid black;
background: gray;
height: 100%;/*Not sure 100% of what ? Parent ???*/
**display: table-row;**
}

How to avoid absolute bottom positioned div from overlapping other when window is resized

I have a page where I have a div at the bottom of the page which when clicked shows another div, just above the bottom div.
I'd like to avoid the footer divs overlapping the content div higher up the page when the window is resized.
The heights of the divs involved shouldn't change.
Is a CSS-only solution possible?
I've created a jsfiddle here
CSS
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
#container {
height: 100%;
width: 100%;
background-color: white;
border: solid #aaa 1px;
padding: 4px;
}
#content {
height: 300px;
border: solid blue 1px;
}
#footer-content {
height: 100px;
border: solid red 1px;
display:none;
}
#footer-footer {
cursor: pointer;
height: 20px;
border: solid cyan 1px;
}
#footer.expanded #footer-content {
display:block;
}
#footer {
position: absolute;
bottom: 0px;
width: 100%;
}
HTML
<div id="container">
<div id="content">content
</div>
<div id="footer">
<div id="footer-content">footer-content</div>
<div id="footer-footer">Click me to expand</div>
</div>
</div>
JS
$("#footer-footer").on("click", function (evt) {
$("#footer").toggleClass("expanded");
});
Simply add position: relative to the #container. This way the absolute positioning of the footer refers to the container.
http://jsfiddle.net/5bkznxud/5/
You'll probably notice that in the example above there's always a scrollbar on the right. This is because of the borders and padding on #container. Here's an example with outline (border with no calculated width) and without any padding:
http://jsfiddle.net/5bkznxud/6/
TIP: Always use outline instead of border for blocking a layout OR use box-sizing: border-box. This causes a box' dimensions to also calculate for the border. Otherwise a box with width of 100% and border will span slightly wider than you want.
It can be solved by using calc().
In this case you can create a jQuery function that get the height of footer-content and footer-footer -> .height(). Without jQuery, I don't think it's possible.
Here is an example:
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
#container {
height: 100%;
width: 100%;
background-color: white;
border: solid #aaa 1px;
padding: 4px;
min-height: 420px;
}
#content {
height:calc(100% - 135px);
border: solid blue 1px;
}
#footer-content {
height: 100px;
border: solid red 1px;
display:none;
}
#footer-footer {
cursor: pointer;
height: 20px;
border: solid cyan 1px;
}
#footer.expanded #footer-content {
display:block;
}
#footer {
position: absolute;
bottom: 0px;
width: 100%;
}
http://jsfiddle.net/dokmngv0/
Browser support for the calc() feature: http://caniuse.com/#feat=calc

<div> inside another <div> same percentage but inner overlaps?

I've got a div within a div, both are percentage based for the page but the nested div overlaps slightly to the right.
I'm actually trying to get the white box sit inside the first light blue div with a small margin on all sides so you can see a bit of the darker backround color, making it stand out more.
Editing to point out that the point of the position:fixed is to make the white box move as you scroll.
A solution was posted that involved chaning the position to relative, although this obviously stops the box from moving.
JSFiddle
div {
border-radius: 5px;
}
#header {
height: 50px;
background-color: #F38630;
margin-bottom: 10px;
}
.left {
height: 1300px;
width: 25%;
background-color: #A7DBD8;
float: left;
margin-bottom: 10px;
}
.right {
height: 1300px;
width: 75%;
background-color: #E0E4CC;
float: right;
margin-bottom: 10px;
}
#footer {
height: 50px;
background-color: #69D2E7;
clear: both;
}
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
<html>
<head>
<title>Result</title>
</head>
<body>
<div id="header"></div>
<div class="left"><div id="fixedleft"></div></div>
<div class="right"></div>
<div id="footer"></div>
</body>
</html>
Your margin is increasing with the width.
Try:
#fixedleft {
height: 50px;
width: calc(25% - 2px);
background-color: #FFFFFF;
position: fixed;
margin: 1px;
}
I guess that this issue is due to default body margin as it doesn't affect the width of your fixed div(as you can see in the example, it's width is always the same, no matter what margin value you set, unlike it's container's width) :
body { margin:0; }
There is still a problem with the inner margin (1px) that pushes it out of the container, you can use calc for it, here is an example:
JSFiddle
#fixedleft {
background-color: #ffffff;
height: 50px;
margin: 2px;
position: relative;
width: 98%;
}
Please try this instear of
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
if you load jQuery..
$(window).bind("resize", function(){
$("#fixedleft").width( parseInt($(".left").width()) -2)
})
$(function(){$(window).resize()})

Sticky footer overflow issue?

I am having some trouble with my sticky footer. First of all, my content does not reach the entire bottom of the screen (even underneath the footer .. check on larger monitor). Also, when the window is smaller than the content, the header moves and does not expand 100% in width when you move the horizontal scrollbar. What am i doing wrong?
Here is my testing site: My Site
If you use firebug or Google Chrome's built in Inspect Element, you can see where all the elements are.
Here is some of the css:
.content
{
width: 1100px;
margin: 0 auto;
border-left:1px solid #000;
border-right: 1px solid #000;
background:#222;
min-height: 100%;
height: 100%;
padding-bottom:50px; /* Padding for footer (width) */
}
.contentInner
{
padding:0px 10px 0px 10px;
min-height: 100%;
height: 100%;
}
.footer
{
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
background: #000; /* So you can see it */
}
Here is what it looks like when the content is bigger than the window:
I would also like the Content to extent all the way down the page with the content!
Edit / add your css like this to get rid of smaller screen issues..
.mainContainer {
min-width: 1100px;
}
To get that content background to continue all way down, i suggest using centered background image in .mainContainer and remove content background OR just set .content min-height to some large value like 900px OR use javascript to set content height if smaller than screen height.
if you put your .mainContainer to the width of your .content, it will work.
.mainContainer {
width: 1100px;
}
Is it what you want ?
Replace your CSS to this one.
.content
{
width: 100%;
margin: 0 auto;
border-left:1px solid #000;
border-right: 1px solid #000;
background:#222;
min-height: auto;
height: auto;
padding-bottom:50px;
position:absolute;
}
.contentInner
{
padding:0px 10px 0px 10px;
min-height: auto;
height: auto;
}
.footer
{
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
background: #000;
}

Horizontal scrollbar bug when minimising window

I'm encountering some difficulty with some CSS I'm coding.
Whenever I minimise the window a horizontal scrollbar appears and the problem with this scrollbar is that it doesn't go away even when I maximise the window.
What could I be doing wrong?
Thanks in advance
CSS
body {
background-color: #C5C5C5;
margin-left: 0px;
margin-top: 0px;
}
html {
overflow-y: scroll;
}
.header_bg {
background-color: #F1F1EE;
padding: 10px 10px 10px 10px;
border-top: 2px solid #738ebe;
width: 100%;
}
.header_main {
width: 960px; // would it be better to change this to width: 80%
margin:0 auto;
overflow: hidden;
}
.header_main img {
float: left;
}
.header_main div {
float: right;
}
HTML
<div class="header_bg">
<div class="header_main">
<img src="resources/img/login_logo.png" width="163" height="66" />
<div>Already a member? Sign in</div>
</div>
</div>​
This:
.header_bg {
background-color: #F1F1EE;
padding: 10px 10px 10px 10px;
border-top: 2px solid #738ebe;
width: 100%;
}
Is adding to the calculated width of it's container, ie, body, which header_bg is stretching to fit 100%, so the padding is shifting bodys dimensions beyond the viewport, thus triggering scroll-x.
Remove it and your scroll bar goes away:
padding: 10px 0;
Edit: http://jsfiddle.net/userdude/782fc/2/
Full: http://jsfiddle.net/userdude/782fc/2/embedded/result
Or, alternatively, put the width on the body with margin: 0 auto; so it auto-centers:
body {
background-color: #C5C5C5;
width: 1024px;
margin: 0 auto;
}
...
.header_bg {
background-color: #F1F1EE;
padding: 10px;
border-top: 2px solid #738ebe;
width: 100%;
}
.header_main {
width: 100%;
margin:0 auto;
overflow: hidden;
}
Edit: http://jsfiddle.net/userdude/782fc/4/
Full: http://jsfiddle.net/userdude/782fc/4/embedded/result/