Reputation: 13
this is a problem only in mobile. here's the image https://i.sstatic.net/LvS77.png
this is the navbar html:
<div class="topnav" id="myTopnav">
<a href="/" class="logo">LOGO</a>
<a href="/example">example</a>
<a href="javascript:void(0);" class="icon" onclick="mob()">
<i class="bars">
<div></div>
<div></div>
<div></div>
</i>
</a>
</div>
and this is the css:
.topnav {
background-color: #333;
overflow: hidden;
}
.topnav a {
float: right;
display: block;
color: #dfdfdf;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.bars div {
width: 35px;
height: 5px;
background-color: black;
margin: 6px 0;
}
.topnav .icon {
display: none;
}
.topnav .logo {
float:left;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
p.s. the responsive class is added with javascript when the three bars in mobile is clicked
Thanks
Upvotes: 0
Views: 242
Reputation: 5982
I added this css
.topnav .logo {
flex: 1 1 auto;
text-align: left;
}
.topnav {
display: flex;
}
Is this something you want?
Don't use float in your css. We have amazing css properties flexbox
for layouting. Float destroys layouting.
.topnav {
background-color: #333;
overflow: hidden;
display: flex;
}
.topnav a {
display: block;
color: #dfdfdf;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.bars div {
width: 35px;
height: 5px;
background-color: black;
margin: 6px 0;
}
.topnav .icon {
display: none;
}
.topnav .logo {
flex: 1 1 auto;
}
.topnav .logo a {
display: inline-block;
text-align: left;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<div class="topnav" id="myTopnav">
<div class="logo">
<a href="/" class="">LOGO</a>
</div>
<a href="/example">example</a>
<a href="javascript:void(0);" class="icon" onclick="mob()">
<i class="bars">
<div></div>
<div></div>
<div></div>
</i>
</a>
</div>
Upvotes: 2