HTML CSS MegaMenu from SharePoint List structure and HTML User Interface

Mega Menu UI:



List structure:



Code:

 <!DOCTYPE html>

<html>

<head>
    <link rel="stylesheet"
        href="https://plainsmidstream.sharepoint.com/sites/OCC/SiteAssets/fontawesome-free-5.15.3-web/css/all.css">
    <style>
        /*hide side navigation and center align*/
        #s4-workspace {
            overflow-xhidden;
        }

        #contentBox {
            margin-left20px;
        }

        #sideNavBox {
            displaynone;
            margin0;
            width0px;
        }
/*----------------------------------------*/
        * {
            box-sizingborder-box;
        }

        body {
            margin0;
        }

        .menubar {
            width96%;
            positionabsolute;
        }

        .navbar {
            overflowhidden;
            background-color#104E8B;
        }

        .navbar a {
            floatleft;
            font-size14px;
            colorwhite;
            text-aligncenter;
            padding14px 16px;
            text-decorationnone;
            font-weight700;
        }

        .navbar .dropdown {
            font-weight700;
        }

        .dropdown {
            floatleft;
            overflowhidden;
        }

        .dropdown .dropbtn {
            font-size16px;
            bordernone;
            outlinenone;
            colorwhite;
            padding14px 16px;
            background-colorinherit;
            fontinherit;
            margin0;
        }

        .dropdown-content {
            displaynone;
            positionabsolute;
            background-color#f9f9f9;
            width100%;
            left0;
            box-shadow0 .5rem 1rem rgba(000.15);
            z-index1;
            padding1px 0px;
            heightauto;
        }

        .dropdown-content .header {
            backgroundred;
            padding16px;
            colorwhite;
        }

        .dropdown:hover .dropdown-content {
            displayblock;
        }

        /* Create three equal columns that floats next to each other */
        .column {
            floatleft;
            widthcalc(100% / 4);
            padding10px;
            text-aligncenter;
            height100px;
            background-repeatno-repeat;
            displayflex;
            flex-directioncolumn;
            justify-contentcenter;
            align-itemscenter;
            background-positioncenter;
            background-size100% 100%;
        }

        .column a {
            floatnone;
            colorblack;
            padding16px;
            text-decorationnone;
            displayblock;
            text-alignleft;
        }

        /* Create three equal columns that floats next to each other */
        .othersectioncolumn {
            floatleft;
            widthcalc(100% / 3);
            padding10px;
            text-aligncenter;
            height100px;
            background-repeatno-repeat;
            displayflex;
            flex-directioncolumn;
            justify-contentcenter;
            align-itemscenter;
            background-positioncenter;
            background-size100% 100%;
        }

        .othersectioncolumn a {
            floatnone;
            color#fff;
            padding16px;
            text-decorationnone;
            displayblock;
            text-alignleft;
        }

        /* Clear floats after the columns */
        .row:after {
            content"";
            displaytable;
            clearboth;
        }
    </style>
    <script src="../SiteAssets/JS/jquery.min.js"></script>
    <script>
        var megamenudata = [];
        $(document).ready(function () {
            MegaMenuList();
        });
        $(".megamenudiv").html("");

        function MegaMenuList() {
            var urlForAllItems = "/_api/Web/Lists/GetByTitle('MegaMenu')/Items?$select=*,SubheaderTag/Title&$expand=SubheaderTag&$orderby=categoryorder,OrderNumber asc";
            $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl + urlForAllItems,
                type: "GET",
                headers: {
                    "accept": "application/json;odata=verbose",
                },
                success: function (data) {
                    megamenudata = data.d.results;
                    $.each(megamenudatafunction (in) {
                        if (n.Category == "SingleHeader") {
                            $(".megamenudiv").append("<a href='" + n.LinkLocation.Url + "''>" + n.Title + "</a>");
                        }
                        if (n.Category == "DropdownHeader") {
                            var titleVar = n.Title.replace(/\s/g'');
                            $(".megamenudiv").append("<div class='dropdown'><div class='dropbtn'>" + n.Title + "&nbsp<i class='fa fa-caret-down'></i></div><div class='dropdown-content'><div class='fullwidthdiv_" + titleVar + "'></div></div></div>");
                        }
                    });
                    $.each(megamenudatafunction (in) {
                        if(n.HeaderType== "Subheader"){
                            var backgroundimg = n.BackgroundImageLocation?n.BackgroundImageLocation.Url:"../SiteAssets/Images/individual%20page.PNG";
                            var hyperlink = n.LinkLocation?n.LinkLocation.Url:"";
                            var subheadertag = n.SubheaderTag?n.SubheaderTag.Title.replace(/\s/g''):"";
                            if(subheadertag!=""){
                                $(".fullwidthdiv_"+subheadertag).append("<div class='column' style='background-image:url(" + backgroundimg + ")'><a href=" + hyperlink + ">" + n.Title + "</a></div>");
                            }
                        }
                    });
                },
                error: function (error) {
                    alert(JSON.stringify(error));
                }
            });
        }
    </script>
</head>

<body>
    <div class="menubar">
        <div class="navbar">
            <div class="megamenudiv"></div>
        </div>
    </div>
    <br />
</body>

</html>

Comments