-2

I have a react header component that looks like this:

const Header = () => {
    return (
        <div className="navbar">
            <div className="logo-container">
                <img id='logo' alt='header-logo' src={Logo}/><span id="header-title">Dashboard</span>
            </div>
        </div>
    );
}

export default Header;

The stylesheet for this component looks like

.navbar {
    height: 4em;
    background-color: #f9f9f9;
    width: 100%;
    background: #00bceb;
  }

  #logo {
    margin-left: 2em
  }

  #header-title {
    display: inline-block;
    vertical-align: middle;
    margin-left: 0.5em;
    color: #f9f9f9;
  }

enter image description here

(I'm hiding the logo)

The text is not middle aligned.

Any help?

Dawn17
  • 5,159
  • 8
  • 32
  • 79

2 Answers2

5

Try using Flexbox:

.logo-container {
   display:flex;
   align-items: center;
}
Minal Chauhan
  • 5,739
  • 5
  • 15
  • 36
  • Wow that was simple. I thought using `align-items: center` would just align horizontally. Thanks – Dawn17 Aug 13 '19 at 06:18
  • @Dawn17 If this answer has helped you, please mark it as correct answer by clicking on the tick. – Gosi Aug 13 '19 at 07:13
0

Use this css, it will work.

.navbar {
   display:flex;
   align-items: center;
}