submenu being shown when user isn't logged in

The following is how the sub-menu is intended for use https://i.imgur.com/p0MHIhu.png

However, upon logging out the sub-menu is also showing - https://i.imgur.com/1J7DbJU.png - which is the issue (I would like the menu to only show up when the user is logged in).

ul.sub-menu {
    posiiton:absolute;
}

.navClass > ul > li{
    font-family: arial;
    padding-left: 10%;
    margin-top: -77px;
    font-size: 16px;
}

.navClass > ul{
    font-size:20px;
    font-family: sans-serif
}

ul.sub-menu{
    position:absolute;
    background-color: #cacdce;
    list-style-type:none;
    margin-top:5px;
    margin-left:-25px;
    width:125px;
    padding-left:0px;
    opacity:0;
}

ul.sub-menu li{
    padding-left:20px;
    padding-top:5px;
    padding-bottom:5px;
   
}
ul.sub-menu li:hover{
}
.navClass li:hover{
}
.navClass li:hover .sub-menu {
    z-index:1;
    opacity:1;
}

<?php 
	include_once 'header.php';
?>

 <div class="main-wrapper">
<section class="main-container">
    <div class="awesome">
    <nav class='navClass'>
    <ul>
        <li>
        <?php
            if (isset($_SESSION['u_id'])) {
                echo $_SESSION['u_uid'];
            }
        ?>
        <ul class="sub-menu">
                <li>About</li>
                <li>Profile</li>
                <li>Dashboard</li>
    </div>
    </div>
    </section>

<?php 
	include_once 'footer.php';
?>

<?php

?>

Any ideas on how to fix this would be greatly appreciated everything is provided above.

Cheers.

1 answer

  • answered 2018-04-14 16:56 xuhaib

    Move <ul class="sub-menu"> or <nav class='navClass'> or the top parent tag for sub-menu inside of the if statement, like:

        <?php if (isset($_SESSION['u_id'])) {
                echo $_SESSION['u_uid']; ?>
                <ul class="sub-menu">
                    <li>About</li>
                    <li>Profile</li>
                    <li>Dashboard</li>
        <?php } ?>
    

    Also, on an unrelated but important note, do check your html structure and all the tags as many of the tags are not closed and hierarchy also seems out a little.