The following code is a website with a nav-bar on it. It uses some simple JavaScript to make it work:
index.html:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>SigmaCubes - Home</title>
<meta name="author" content="Julian Lachniet,Simon Kwilinski,Jacob Wysko" />
<meta name="description" content="SigmaCubes is the best website on the internet." />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link href="https://fonts.googleapis.com/css?family=Lato|Noto+Sans|Nunito:600|Material+Icons" rel="stylesheet" type="text/css" />
<link href="/lib/css/reset.css" rel="stylesheet" type="text/css" />
<link href="/lib/css/sigmacubes.css" rel="stylesheet" type="text/css" />
<link href="/favicon.ico" rel="shortcut icon" />
<script src="/lib/js/main.js"></script>
</head>
<body onload="main()">
<noscript>
<div class="error">
<h1>Error:</h1>
<h2>Your browser does not currently support JavaScript which is required to view this page.</h2>
</div>
</noscript>
<!--[if IE]>
<div class="error">
<h1>Error:</h1>
<h2>Your browser is not supported by SigmaCubes.</h2>
</div>
<![endif]-->
<div class="hidden" id="nav-large">
<img alt="SigmaCubes Logo" id="logo_h" height="24" src="/img/logo_h.svg" />
<div id="nav-large-links">
<a class="link-large" href="#">About Us</a>
<a class="link-large" href="#">Projects</a>
<a class="link-large" href="#">Contact</a>
<a class="link-large" href="#">Donate</a>
</div>
</div>
<div class="hidden" id="nav-small">
<img alt="SigmaCubes Logo" id="logo_h" height="24" src="/img/logo_h.svg" />
<a class="link-nav" onclick="toggleNav()" href="javascript:void(0);">
<img height="28" src="/img/menu.svg" />
</a>
</div>
<div class="hidden" id="nav-small-links">
<a class="link-small" href="#">About Us</a>
<a class="link-small" href="#">Projects</a>
<a class="link-small" href="#">Contact</a>
<a class="link-small" href="#">Donate</a>
</div>
<div class="hidden" id="nav-stupid">
<div class="error">
<h1>Error:</h1>
<h2>Your window size is too small to view this page correctly. Please resize the window.</h2>
</div>
</div>
<div id="wrapper">
<img id="hq" src="img/hq.jpg" />
</div>
</body>
</html>
reset.css:
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p,
blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img,
ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i,
center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption,
tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section,
summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav,
section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after, q:before, q:after {
content: "";
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
sigmacubes.css:
body {
background-color: #ddd;
font-family: "Noto Sans", sans-serif;
}
h1 {
font-size: 24px;
margin: 4px 16px;
}
h2 {
font-size: 18px;
margin: 16px;
}
.error {
padding: 16px;
}
.hidden {
display: none;
}
.link-large {
color: #000;
padding: 0 8px;
text-decoration: none;
}
.link-large:hover {
color: #00f;
}
.link-nav {
position: absolute;
right: 16px;
top: 10px;
}
.link-small {
color: #fff;
display: block;
padding: 8px;
text-decoration: none;
}
.link-small:hover {
color: #88f;
}
#hq {
width: 100%;
}
#logo_h {
left: 16px;
position: absolute;
top: 10px;
}
#wrapper {
text-align: center;
}
#nav-large, #nav-small {
background-color: #63a4ff;
font-family: "Nunito", sans-serif;
font-size: 16px;
height: 16px;
padding: 16px 0;
text-align: right;
}
#nav-large-links {
display: inline;
margin: 0 16px;
}
#nav-small-links {
background-color: #393f47;
}
main.js:
var screenMode = "none", nav = false;
function main() {
setInterval(function(){updateLayout()}, 10);
}
function updateLayout() {
var width = window.innerWidth;
if (width < 250 & screenMode != "stupid") {
screenMode = "stupid"
setDisplay("nav-stupid", "block");
setDisplay("nav-small", "none");
setDisplay("nav-small-links", "none");
setDisplay("nav-large", "none");
} else if (width > 249 && width < 500 && screenMode != "mobile") {
screenMode = "mobile"
setDisplay("nav-stupid", "none");
setDisplay("nav-small", "block");
setDisplay("nav-small-links", "none");
setDisplay("nav-large", "none");
} else if (width > 499 && screenMode != "desktop") {
screenMode = "desktop"
setDisplay("nav-stupid", "none");
setDisplay("nav-small", "none");
setDisplay("nav-small-links", "none");
setDisplay("nav-large", "block");
}
}
function toggleNav() {
if (nav) {
setDisplay("nav-small-links", "none");
nav = false;
} else {
setDisplay("nav-small-links", "block");
nav = true;
}
}
function setDisplay(id, state) {
document.getElementById(id).style.display = state;
}