Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                  <div class="h-wrap">

            <header>
                <section id="top-bar">
                    <div id="c-info">Kontakt@mg-otterson.de</div>    
                    <h1>animierte Kopfzeile</h1>

                </section>
            </header>
            <nav>
                <div id="burger-menu">
                    <div class="stripe"></div>
                    <div class="stripe"></div>
                    <div class="stripe"></div>
                </div>
                <ul><li><a>Seite 1</a>
                        <ul>
                            <li><a>Unterseite 1</a></li>
                            <li><a>Unterseite 2</a></li>
                            <li><a>Unterseite 3</a></li>
                        </ul>
                    </li>

                    <li><a>Seite 2</a>
                        <ul>
                            <li><a>Unterseite 4</a></li>
                            <li><a>Unterseite 5</a></li>
                        </ul>
                    </li>

                    <li><a>Seite 3</a></li>
                    <li><a>Seite 4</a></li>
                    <li><a>Seite 5</a></li>
                    <li><a>Seite 6</a></li>
                    <li><a>Seite 6</a></li>
                    <li><a>Seite 6</a></li>
                </ul> 

            </nav>    
        </div>
        <article>
            <div>
                <h1>Animierte fixierte Menüleiste</h1>
                <h2>Demo HTML</h2>
                <p>
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. 
                    Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, 
                    pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, 
                    vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede 
                    mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. 
                    Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, 
                    feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. 
                    Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. 
                    Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. 
                    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. 
                    Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. 
                    Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, 
                    augue velit cursus nunc,
                </p>
                <img src="https://mg-otterson.de/fileadmin/animierte-kopfzeile/hostimages/bild1.jpg">
                <p>
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. 
                    Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, 
                    pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, 
                    vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede 
                    mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. 
                    Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, 
                    feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. 
                    Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. 
                    Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. 
                    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. 
                    Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. 
                    Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, 
                    augue velit cursus nunc,
                </p>
            </div>
        </article>
        <footer>kontakt@mg-otterson.de</footer>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400&display=swap');
* {
    box-sizing: border-box;
}

body { 
    overflow: visible;
}
/* Navigation Anfang */
nav {
    text-align: center;
    overflow: visible;
    height: auto;
    background: #444;
    position: relative;
    overflow: visible;
}
nav>ul {
    margin:0;
    padding:0;
    text-align: center;
    overflow:visible;
    background:#333;
}
nav ul ul { 

    display: none;
    padding: 0;
    margin-top: 0px;
    width:227px;
    position: absolute;
    z-index: 1000;
    background: #444;
}
nav ul li:hover ul {
    display:block;
}
nav ul>li {
    display:inline-block;
    list-style: none;
}
nav ul>li a  {
    padding: 25px 20px;
    display: block;
}
nav ul li  li a  {
    padding: 5px 20px;
    display: block;
}
nav li:hover ul {
    display:block;
}
nav ul ul li {
    padding: 10px 20px;
    text-align: left;
    display: block;
    position: relative;
}
nav a{
    color:#ccc;
    text-decoration: none;
    font-size:18px;
}
@media only screen and (max-width: 630px) {
    nav ul>li { 
        width:100%;
    }
    nav>ul {
        display:none;
        margin-top: 0px;
    }
    nav>ul>li {
        position: relative;
        width:100%;
        padding: 10px 20px;
    }
    nav ul ul {
        position: relative;
        width:100%;
    }
    nav ul ul li {
        text-align: center;
        margin:0;
        margin-bottom:-15px;
    }
    #burger-menu { 
        display:block !important;
    }
    nav ul li:hover ul {
        display:none;
    }
    nav ul>li a  {
    padding: 5px 20px;
    display: block;
}
}
@media only screen and (min-width: 630px) {
    nav>ul {
        display:block !important;
        margin-top:0px;
    }
}
#burger-menu {
    position: absolute;
    right:20px;
    top:20px;
    width:30px;
    height:30px;
    display:none;
}
.arrow {
    background:url(https://mg-otterson.de//fileadmin/animierte-kopfzeile/hostimages/arrow.png);
    height:25px;
    width:25px;
    background-size: 15px 15px;
    background-repeat:no-repeat;
    background-position:center center;
    position:absolute;
    right:25px;
    top:10px;
}

.rotate {
    transform:rotate(180deg);
}
.act,.act-ul {
    display:block !important;
}
/* Navigation Ende */
h1,h2,h3,h4 {
    font-weight: 400;
}
body {
    min-height:100vh;
    margin:0;
    padding:0;
    font-family:Arial, sans-serif;
    font-family: 'Roboto';
    font-weight: 300;
}
header {
    width:100%;
    background:#444;
    overflow: visible;
    position: relative;
    top:0;
    left:0;
}
#c-info {
    color:#fff;
}
.stripe {
    position: relative;
    width:100%;
    height:4px;
    background:#ccc;
    margin-bottom:5px;
}
article {
    width:100%;
    max-width:1300px;
    margin:0 auto;
    margin-top:0px;
    font-size:18px;
    line-height:1.5;
    padding:30px;
    background:#fafafa;
    border-left:1px solid #ccc;
    border-right:1px solid #ccc;
    border-bottom:1px solid #ccc;
}
h1 {
    font-size:40px;
    margin:0 0 30px 0;
}
h2 {
    font-size:30px;
    margin:0 0 30px 0;
}
article img {
    margin:30px 0;
    width:100%;
    max-width:800px;
}
footer {
    text-align: center;
    padding:30px 20px;
    margin-top: 0px;
}
#top-bar {
    width:100%;
    min-height:200px;
    background: #000;
    display: flex;
    flex-wrap: nowrap;
    align-content: center;
    justify-content: center;
    align-items: center;
    position: relative;
    flex-direction: column;
}
@media only screen and (max-width: 900px) {
    #top-bar {
        width:100%;
        min-height:150px;
    }
}
#top-bar h1 {
    color:#fff;
    margin:0;
}
.fixed {
    position:fixed;
    top:0;
    left:0;
    width: 100%;
}
.smoothed-in {
    transition: top 1s;
}
 
a {
    cursor:pointer;
}
              
            
!

JS

              
                
    var topBarHeight,
        navHeight,
        offset,
        offsetFactor,
        startFix = false,
        isMobileNav = false;
const   breakingPointFixed = 630,
        body = document.querySelector("body"),
        topBar = document.querySelector("#top-bar"),
        navigation = document.querySelector("nav"),
        mobileNavigationHeight = "70px",
        menuItems = document.querySelectorAll("nav > ul > li > a"),
        scrollPaddingTop = "10px",
        scrollPaddingBottom = "10px",
        mobileFixed = true;

document.fonts.ready.then(function () {
    setAll();
});

function setFactor() {
    let navHeightSingle = menuItems[0].offsetHeight;
    if (navigation.offsetHeight > navHeightSingle) {
        let div = Math.floor(navigation.offsetHeight / navHeightSingle);
        offsetFactor = div;
    } else {
        offsetFactor = 1;
    }
}
function setAll() {
    navHeight = navigation.offsetHeight;
    topBarHeight = topBar.offsetHeight;
    setFactor();
    let defaultPaddingTop = getComputedStyle(menuItems[0]).paddingTop;
    let defaultPaddingBottom = getComputedStyle(menuItems[0]).paddingBottom;
    offset = parseInt(defaultPaddingTop) + parseInt(defaultPaddingBottom) - parseInt(scrollPaddingTop) - parseInt(scrollPaddingBottom);
    navigation.style.cssText = "top:" + (navHeight * -1) + "px;margin-top:" + navHeight + "px;";
    function setFixed() {
        navigation.classList.add("fixed");
        navigation.classList.add("smoothed-in");
        navigation.style.cssText = "top:" + (navHeight) + "px;margin-top:" + (navHeight * -1) + "px;";
        body.style.paddingTop = navHeight + "px";
    }
    function removeScrollPadding() {
        for (let menuItem of  menuItems) {
            menuItem.style.padding = "";
        }
    }
    window.addEventListener("scroll", function (event) {
        var scrollPos = window.scrollY;
        if (!isMobileNav) {
            if (!startFix) {
                startFix = true;
                return false;
            }
            if (scrollPos > topBarHeight + 1 * navHeight) {
                navigation.style.marginBottom = "0px";
                for (let menuItem of  menuItems) {
                    menuItem.style.cssText = "padding-top:" + scrollPaddingTop + ";padding-bottom:" + scrollPaddingBottom + ";";
                }
                setFixed();
            } else if (scrollPos <= topBarHeight + offset * offsetFactor) {
                navigation.style.cssText = "top:0px;margin-top:0px;";
                navigation.classList.remove("fixed");
                navigation.classList.remove("smoothed-in");
                body.style.paddingTop = "0px";
                removeScrollPadding();
                if (isMobileNav) {
                    navigation.style.marginTop = "0px";
                    navHeight = navigation.offsetHeight;
                    topBarHeight = topBar.offsetHeight;
                    removeScrollPadding();
                }
            }
        } else {
            if (scrollPos > topBarHeight && mobileFixed) {
                navigation.classList.add("fixed");
                body.style.paddingTop = navHeight + "px";
            } else if (scrollPos <= topBarHeight) {
                body.style.paddingTop = "0px";
                navigation.classList.remove("fixed");
            }
        }
    });
    navigation.style.marginBottom = (-1 * navHeight) + "px";
    if (window.innerWidth < breakingPointFixed) {
        setMobileNav();
    } else {
        isMobileNav = false;
    }
}
function setMobileNav() {
    isMobileNav = true;
    navigation.classList.remove("fixed");
    navigation.style.cssText = "top:0px;margin-top:0;height:" + mobileNavigationHeight + ";padding-top:" + mobileNavigationHeight + ";";
    navigation.classList.remove("smoothed-in");
    navHeight = navigation.offsetHeight;
    navigation.style.height = mobileNavigationHeight + "px";
}
window.addEventListener("resize", () => {
    setFactor();
    navHeight = navigation.offsetHeight;
    topBarHeight = topBar.offsetHeight;
    if (window.innerWidth < breakingPointFixed) {
        setMobileNav();
        body.style.paddingTop = "";
        navigation.style.marginBottom = "";
    } else {
        navigation.style.paddingTop = "";
        navigation.style.height = "";
        isMobileNav = false;
    }
});
/* --------- NAVIGATION ---------- */

var ifArrows = false;
const breakingPoint = 630;
function removeArrows() {
    if (document.querySelectorAll(".arrow").length > 0) {
        for (let elIn of document.querySelectorAll("nav .in")) {
            let parent = elIn.parentNode;
            while (elIn.firstChild)
                parent.insertBefore(elIn.firstChild, elIn);
            parent.removeChild(elIn);
        }
        for (let arrEl of document.querySelectorAll(".arrow")) {
            arrEl.remove();
        }
        ifArrows = false;
    }
}
function setArrows() {
    if (!document.querySelectorAll(".arrow").length) {
        for (let navUl of document.querySelectorAll("nav ul li ul")) {
            let wrapEl = navUl.closest("li").querySelector("a");
            let wrapper = document.createElement('div');
            wrapper.className = "in";
            wrapEl.parentNode.insertBefore(wrapper, wrapEl);
            wrapper.appendChild(wrapEl);
        }
        for (let inEl of document.querySelectorAll(".in")) {
            let arr = document.createElement('div');
            arr.className = "arrow";
            inEl.appendChild(arr);
        }
    }
    if (!ifArrows) {
        clickArrows();
        ifArrows = true;
    }
}
for (let navA of document.querySelectorAll("nav>ul>li a")) {
    navA.addEventListener("click", function () {

        if (window.innerWidth < breakingPoint) {
            document.querySelector("nav > ul").classList.remove("act-ul");
            if (!document.querySelectorAll(".act")) {
                document.querySelector(".act").classList.remove("act");
            }
            for (let arrEl of document.querySelectorAll(".arrow")) {
                arrEl.classList.remove("rotate");
            }
        }
    });
}
document.querySelector("#burger-menu").addEventListener("click", function () {
    document.querySelector("nav > ul").classList.toggle("act-ul");
});
if (window.innerWidth < breakingPoint) {
    setArrows();
}

function clickArrows() {
    for (let arrElLink of document.querySelectorAll(".arrow")) {
        arrElLink.addEventListener("click", function (event) {
            event.target.closest("li").querySelector("ul").classList.toggle("act");
            event.target.classList.toggle("rotate");
            let parentLiCur = event.target.closest("li");
            for (let arrEl of document.querySelectorAll(".arrow")) {
                let liList = arrEl.closest("li");
                if (parentLiCur != liList) {
                    arrEl.classList.remove("rotate");
                    arrEl.closest("li").querySelector("ul").classList.remove("act");
                }
            }
        });
    }
}
window.addEventListener("resize", () => {

    for (let ul of  document.querySelectorAll("nav ul li ul")) {
        ul.classList.remove("act");
    }
    for (let arrEl of document.querySelectorAll(".arrow")) {
        arrEl.classList.remove("rotate");
    }
    if (window.innerWidth < breakingPoint) {
        setArrows();
    } else {
        removeArrows();
    }
});
              
            
!
999px

Console