Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

html - Logo image at same line height as text in navigation bar

I'm trying to put my Logo at the same line height as my text inside my navigation bar. Here is an example of what I mean: https://try.talkspace.com

However my logo drops to the bottom of the navigation bar: My navbar

It's not the size of the logo because I have tried a extremely small one and it went to the bottom. Ive also tried creating separate logo class for it, vertical-align: middle and trying to center it.

       <!-- Navigation Bar -->
       <div class="nav_main">
        <h2 class="nav_main_logo"><img src="fca.svg" class="nav_main_logo"></h2>
         <input type="checkbox" id="chk">
          <label for="chk" class="show-menu-btn">
           <i class="fa fa-bars"></i>
          </label>
           <ul class="nav_menu_main">
             <a href="#">Home</a>
             <a href="#">Services</a>
             <a href="#">Resources</a>
             <a href="#">Employment</a>
             <a href="#">The Team</a>
             <label for="chk" class="hide-menu-btn">
               <i class="fa fa-times"></i>
             </label>
           </ul>
         </div>



 @import url('https://fonts.googleapis.com/css2?family=Sriracha&display=swap');
*{
  margin: 0;
  padding: 0;
  text-decoration: none;
}
.nav_main {
  height: 100px;
  background-color: #fff;
  padding: 0 20px;
  color: red;
}
.nav_main_logo {
  line-height: 100px;
  float: left;
  text-transform: uppercase;
  vertical-align: middle;
}
.nav_menu_main {
  float: right;
  line-height: 100px;
}
.nav_menu_main a {
  color: #005368;
  text-transform: uppercase;
  padding: 0 10px;
  transition: 0.4s;
  font-family: 'Sriracha', cursive;
}
.show-menu-btn,.hide-menu-btn {
  transition: 0.4s;
  font-size: 30px;
  cursor: pointer;
  display: none;
}
.show-menu-btn {
  float: right;
}
.show-menu-btn i {
  line-height: 100px;
}

/* TODO: Active tab
.nav_menu_main a.active
TODO: .hover */

.show-menu-btn:hover,
.hide-menu-btn:hover {
  color: blue;
}

#chk {
  position: absolute;
  visibility: hidden;
  z-index: -1111;
}

@media screen and (max-width:800px) {
  .show-menu-btn,.hide-menu-btn {
    display: block;
  }
  .nav_menu_main {
    position: fixed;
    width: 100%;
    height: 100vh;
    background: #333;
    right: -100%;
    top: 0;
    text-align: center;
    padding: 80px 0;
    line-height: normal;
    transition: 0.7s;
  }
  .nav_menu_main a {
    display: block;
    padding: 20px;
  }
  .hide-menu-btn {
    position: absolute;
    top: 40px;
    right: 40px;
  }
  #chk:checked ~ .nav_menu_main {
    right: 0;
  }
}
question from:https://stackoverflow.com/questions/66061114/logo-image-at-same-line-height-as-text-in-navigation-bar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try putting display on inline-block or inline and then vertical-align: middle for nav_main_logo. This usually fixed my problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...