Search code examples
htmlcssmobilemenuresponsiveness

css menu disappears on mobile device


Here's my CSS menu I've created.

When I see this in my mobile (iPhone 6), the last menu (Menu4) does not show At All. The first 3 menus stretch from left to the right of the phone screen. I can't figure out why.

Could someone help out please?

Here's the HTML part

 <hr class="navHr">
 <nav id="m">
   <a href="#" data-mirror="Menu1">Menu1</a>
   <a href="#" data-mirror="Menu2">Menu2</a>
   <a href="#" data-mirror="Menu3">Menu3</a>
   <a href="#" data-mirror="Menu4">Menu4</a>
 </nav>
 <hr class="navHr">

And the CSS part

.navHr {
    border: 0;
    height: 0.1em;
    margin: 0;
    background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
    background-image: -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
    background-image: -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
    background-image: -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0)); 
}



nav {
    height: 2em;
    background: #000;
    background: linear-gradient(to bottom, rgba(76, 76, 76, 1) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 );
    line-height: 2em;
    text-transform: uppercase;
    text-align: center;
    min-width: 2em;
    position: relative;
}
nav::before {
    background: linear-gradient(to top, rgba(76, 76, 76, 0) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
    content: '';
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.09;
}
nav a {
    color: #FFF;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.2em;
    border-right: solid 0.1em #FFF;
    height: 100%;
    padding: 0.25em 3em;
    position: relative;
}

nav a:first-child {
    border-left: solid 0.1em #FFF;
}
nav a::before {
    content: attr(data-mirror); 
    position: absolute;
    top: 100%;
    left: 3em;
    color: #000;
    transform: scaleY(-1);
    color: #FFF;
    opacity: 0.5;
}

#m {
    background-color: #000000;
}

Solution

  • I've checked on your code, try adding "display:inline-block" on your anchor tag, and you will see your column 4 appearing, the fourth one goes beneath the second one in small screens, since the position is relative, try it here :

    Columns

    Basically, what you are looking for, is displaying an element as an inline-level block container to avoid dislocation. The inside of this block is formatted as block-level box, and the element itself is formatted as an inline-level box, which shapes the navigation of these 4 columns sitting next to each other.

    Why do we use inline-block ?

    • Inline-block makes the element generate a block box that’s laid out as if it were an inline box.
    • An inline block is placed inline (ie. on the same line as adjacent content), but it behaves as a block.
    • Basically, it’s a way to make elements inline, but preserving their block capabilities such as setting width and height, top and bottom margins and paddings etc.