I am trying to use flexbox and have the h1
and nav
on the same line so i have display:flex
with the default direction of row. I want title to be centered and the nav to the right. I was wondering if theres a way to move the navigation all the way to the right. I have tried margin-right:auto
on the h1
and tried to find a property like align-self
for the main axis when its set to row but I cant figure it out. I had justify-content:center
originally but gave up and set it back to space-between
.
import React from 'react';
import { Link } from 'react-router-dom';
const Header = () => {
return (
<header className='header--container'>
<Link to='/'>
<h1 className='header--title'>Cocktail Connaisseur</h1>
</Link>
<Link to='/cocktails/a'>
<nav className='header--nav'>
<p>All Cocktails</p>
</nav>
</Link>
</header>
);
};
export default Header;
index.css
/*Header Styling */
.header--container {
background-color: #55505c;
padding: 15px;
box-shadow: 0px 1px 5px rgba(0, 0, 0, 0.2);
display: flex;
align-items: center;
justify-content: space-between;
}
.header--container>a {
text-decoration: none;
}
.header--title {
margin: 0;
color: #e8e9f3;
font-size: 1.5em;
text-align: center;
}
.header--nav {
align-self: flex-end;
margin-left: auto;
}
.header--nav>p {
margin: 0;
color: #e8e9f3;
}
3
Answers
You can add one more container on top then your output will work perfectly as per your requirement.
add flex:1; to the .header–title and i removed the justify from the container
create a div and place the title into the div:
then in the css:
and it’ll place your title exactly in the center and your nav links on the right.