Fynn Fynn - 11 days ago 9
CSS Question

Scaling problems with responsive Navbar

I tried to create a responsive navbar for my page by following this tutorial: http://www.w3schools.com/howto/howto_js_topnav.asp

After resizing the browser i get the correct view, but when i am using a phone to display my page, everything is really small, like in this picture:
enter image description here

This is the css from the tutorial, just a bit altered:

body {margin:0;}
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #373a3c!important;
}

ul.topnav li {
float: left;
}

ul.topnav li a {
display: inline-block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}

ul.topnav li a:hover {background-color: #555;}

ul.topnav li.icon {display: none;}

@media (orientation: portrait) {
ul.topnav li:not(:first-child) {display: none;}
ul.topnav li.icon {
float: right;
display: inline-block;
}
}

@media (orientation: portrait) {
ul.topnav.responsive {position: relative;}
ul.topnav.responsive li.icon {
position: absolute;
right: 0;
top: 0;
}
ul.topnav.responsive li {
float: none;
display: inline;
}
ul.topnav.responsive li a {
display: block;
text-align: left;
}
}


HTML:

<ul class="topnav" id="myTopnav">
<li class="active" onmouseover="hover();" onmouseout="unhover();">
<a href="./index.html"><img id="logo" src="./images/logo_white.png" /></a>
</li>
<li><a href="./index.html">Sensoren</a></li>
<li><a href="./keyServers.html">Schl&uuml;sselserver</a></li>
<li><a href="./trustSystem.html">Vertrauensgewichtung</a></li>
<li><a href="./pluginManager.html">Plugin-Manager</a></li>
<li><a href="./logEvents.html">Log-Events</a></li>
<li class="icon">
<a href="javascript:void(0);" style="font-size:15px;" onclick="enableBurgerMenu()">☰</a>
</li>
</ul>


Could someone tell me how i could achieve the look on the right on the phone, too?

Answer

You need to add this in your <head>

<meta name="viewport" content="width=device-width, initial-scale=1">

This will ensure that your width is relative to the screen size.

More information here: https://css-tricks.com/snippets/html/responsive-meta-tag/