PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 17, 2022

[FIXED] How can I align button vertically in nav bar?

 November 17, 2022     css, html, vertical-alignment     No comments   

Issue

I'm practicing creating a website, and am currently trying to replicate this site. At the moment I am working on the navigation bar, but I am unable to vertically align the button vertically in the nav.

.header {
  background-color: red;
  padding: 40px 20px;
}

.header h1 {
  background-color: yellow;
  float: left;
}

.header h1 img {
  display: block;
}

.header__nav {
  background-color: aqua;
  float: right;
}

.header__nav li {
  float: left;
  height: 38px;
}

.header__nav li a {
  padding: 0 20px;
  display: inline-block;
  line-height: 38px;
}

.contents {
  background-color: green;
}

.footer {
  background-color: blue;
}
<header class="header clearfix">
  <h1>
    <a href="#"><img src="https://pixelicons.com/wp-content/themes/pexelicons/assets/pic/site-logo/logo.png" alt="Logo"></a>
  </h1>
  <nav class="header__nav">
    <ul class="clearfix">
      <li><a href="#">View icons</a></li>
      <li><a href="#">Buy now</a></li>
      <li><button class="menu">menu</button></li>
    </ul>
  </nav>
</header>
<section class="contents">
  contents
</section>
<footer class="footer">
  footer
</footer>

My working image

I wanna align the top-right button of the nav bar vertically. I know this can be solved using display: flex;, but I wanna solve it another way. Is there a proper way to solve this issue?


Solution

Even though your solution using display: flexseems perfectly fine to me, you could fix it using vertical-align: middle; and display: inline-block on all of the items (the two links and the button)



Answered By - Janis Jansen
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing