Arno Claes
Arno Claes

Reputation: 167

Logo CSS navbar keeps exploding

I realize that this question was asked before by different posters, but I tried a lot of suggested answers and none of them seemed to work. When inputting my logo into the NavBar, it keeps expanding. However, the <li class="logo"> slot is reserved in the navbar, as the left class does leave room, but only as much as their designated 8% width not 40%.

ul.navbar {
  width: 100%;
  height: 50px;
  line-height: 50px;
  list-style-type: none;
  padding: 0;
  background-color: #5D6576;
  opacity: 0.8;
  border: none;
}

li.logo {
  float: left;
  width: 40%;
}

li.left {
  float: left;
  color: white;
  width: 8%;
}

li.left a {
  display: block;
  color: white;
  text-align: center;
  text-decoration: none;
}

li a:hover {
  background-color: #BC80BB;
  transition: 1s;
}

li.right {
  float: right;
  width: 4%;
}
<ul class="navbar">
  <li class="logo"><img src="static/logo.png" alt="Logo"></li>
  <li class="left"><a href="/">Home</a></li>
  <li class="left"><a href="https://www.***.com" target="_blank">*** Website</a></li>
  <li class="right"><a href="mailto:***l@***.com"><i class="fa fa-fw fa-envelope"></i></a></li>
  <li class="right"><a href="tel:***"><i class="fa fa-fw fa-phone"></i></a></li>
</ul>

Extremely expanding logo:

extremely expanding logo

Showing the reserved spot:

showing the reserved spot

Upvotes: 1

Views: 125

Answers (2)

Zak
Zak

Reputation: 61

Following @Revti Shah answer to prevent jumping outside the nav you need to add this

overflow: hidden;

in your code

ul.navbar

or in her code

header-menu

Upvotes: 0

Revti Shah
Revti Shah

Reputation: 642

Here i am sending you code as well as link. Please check it. If any changes then let me know.

https://jsfiddle.net/np6tzxyd/16/

.header-menu {
  display: flex;
  background-color: #5D6576;
  opacity: 0.8;
  width: 100%;
  height: 50px;
  line-height: 50px;
  align-items: center;
  justify-content: space-between;
}

.navbar-left,
.navbar-right {
  display: flex;
  list-style-type: none;
  padding: 0;
  border: none;

}

.navbar-left li,
.navbar-right li {
  padding-right: 15px
}
.navbar-left li a:hover,
.navbar-right li a:hover {
  color: #fff;
}

.logo {
  display: block;
  padding-right: 20px;
}
.logo-menu{
  display: flex;
  align-items: center;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="header-menu">
  <div class="logo-menu">
    <a class="logo"><img src="static/logo.png" alt="Logo"></a>
    <ul class="navbar-left">
      <li><a href="/">Home</a></li>
      <li><a href="https://www.***.com" target="_blank">*** Website</a></li>
    </ul>
  </div>
  <ul class="navbar-right">
    <li><a href="mailto:***l@***.com"><i class="fa fa-fw fa-envelope"></i></a></li>
    <li><a href="tel:***"><i class="fa fa-fw fa-phone"></i></a></li>
  </ul>
</div>

Upvotes: 2

Related Questions