I'm practicing CSS/flexbox reproducing the login page of instagram but i'm facing a issue with horizontal alignment that i can't figure out what's wrong.
There's two major containers inside one big wrapper ("instagram-wraper" - each one get 50% of the width of that wraper).
Container 1 (left): "cellphone-img" that contain only a cellphone img
Container 2 (right): "account-info-container" that contain all the login inputs, subscribe, and so on.
The image on the left side work as intended, but what i'm trying to do is to align all the content in the account-info-container to the left with justify-content, essentially putting the image and the login containers side by side, but it doesn't work. What am i missing? (bet it's something simple...)
Thanks in advance.
PS: I didn't work on the responsiveness yet.
/* General settings */
* {
margin: 0;
padding: 0;
text-decoration: none;
box-sizing: border-box;
text-decoration: none;
font-family: "Roboto";
}
body {
width: 100%;
min-height: 100vh;
background-color: rgb(243, 243, 243);
font-size: 14px;
}
.flex-container {
display: flex;
/* max-width: 1200px; */
margin: auto;
width: 100%;
}
/* Wrapper img + wrapper login */
.instagram-wrapper {
align-items: center;
width: 60%;
height: 85vh;
}
/* Cellphone img container */
.cellphone-img {
display: flex;
align-items: center;
justify-content: flex-end;
width: 50%;
/* margin-left: 150px; */
}
.cellphone-img img {
height: 630px;
width: auto;
}
/* Login + subscribe + ap-downloads */
.account-info-container {
display: flex;
align-items: center;
flex-direction: column;
justify-content: flex-start;
width: 50%;
/* margin-right: 150px; */
}
/* Login wrapper */
.login-container {
flex-direction: column;
height: 420px;
width: 70%;
border: 1px solid rgba(var(--b6a, 219, 219, 219), 1);
background-color: #fff;
}
.insta-logo {
width: 100%;
display: flex;
justify-content: center;
padding-top: 55px;
padding-bottom: 35px;
}
/* Login inputs container */
.login {
align-items: center;
flex-direction: column;
}
.login input {
width: 85%;
height: 36px;
background-color: rgba(var(--b3f, 250, 250, 250), 1);
border: 1px solid rgba(var(--ca6, 219, 219, 219), 1);
border-radius: 3px;
font-size: 13px;
padding-left: 8px;
}
.input-login {
margin-bottom: 10px;
}
.input-password {
margin-bottom: 20px;
}
.login-btn {
width: 85%;
background-color: rgba(var(--d69, 0, 149, 246), 1);
border: 1px solid transparent;
border-radius: 4px;
color: #fff;
font-size: 14px;
padding: 5px 9px;
cursor: pointer;
font-weight: 600;
box-sizing: border-box;
}
.or-ruler {
width: 85%;
color: rgba(var(--f52, 142, 142, 142), 1);
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
margin-top: 20px;
}
.or-ruler::before {
content: "";
width: 120px;
height: 1px;
background-color: rgba(var(--ca6, 219, 219, 219), 1);
}
.or-ruler::after {
content: "";
width: 120px;
height: 1px;
background-color: rgba(var(--ca6, 219, 219, 219), 1);
}
.facebook-login-btn {
width: 85%;
color: #385185;
background-color: transparent;
border: none;
cursor: pointer;
margin: 30px auto;
display: flex;
justify-content: center;
}
.facebook-login-btn img {
width: 17px;
height: auto;
margin-right: 5px;
}
.forget-pass-link {
font-size: 12px;
cursor: pointer;
padding-bottom: 40px;
color: #00376b;
}
/* Subscribe container */
.subscribe {
align-items: center;
justify-content: center;
border: 1px solid rgba(var(--b6a, 219, 219, 219), 1);
background-color: #fff;
height: 70px;
width: 70%;
margin-top: 10px;
margin-bottom: 30px;
}
.subscribe p a {
font-weight: 600;
color: rgba(var(--d69, 0, 149, 246), 1);
}
/* Apps download wrapper */
.app-download {
align-items: center;
flex-direction: column;
width: 70%;
}
.app-imgs {
display: flex;
width: 100%;
justify-content: space-around;
}
.app-imgs img {
width: 170px;
height: auto;
padding-top: 30px;
}
/* Footer */
.footer-section {
max-width: 60%;
height: 100px;
margin: auto;
margin-bottom: 200px;
}
footer {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 12px;
}
footer div {
margin: 8px auto;
}
footer a {
margin: auto 10px;
color: rgba(var(--f52, 142, 142, 142), 1);
text-decoration: none;
}
<div class="instagram-wrapper flex-container">
<div class="cellphone-img">
<img src="./images/instagram-celular2.png" alt="instagram cellphone" />
</div>
<div class="account-info-container">
<div class="login-container flex-container">
<div class="insta-logo">
<img src="./images/instagram-logo.png" alt="instagram-logo" />
</div>
<div class="login flex-container">
<input class="input-login" type="text" placeholder="Telefone, nome do usuário ou email" />
<input class="input-password" type="text" placeholder="Senha" />
<button class="login-btn">Entrar</button>
<div class="or-ruler">
<span> OU <span>
</div>
<button class="facebook-login-btn">
<span><img src="./images/fb-icon.png" alt="" /></span>
<span>Entrar com o Facebook</span>
</button>
<a class="forget-pass-link" href="">Esqueceu a senha?</a>
</div>
</div>
<div class="subscribe flex-container">
<p>Não tem uma conta? Cadastre-se</p>
</div>
<div class="app-download flex-container">
<p>Obtenha o aplicativo.</p>
<div class="app-imgs">
<img src="./images/apple-button.png" alt="appstore-img" />
<img src="./images/googleplay-button.png" alt="googleplay-img" />
</div>
</div>
</div>
</div>
<section class="footer-section">
<footer>
<div>
Meta
About
Blog
Jobs
Help
API
Privacy
Terms
Top Accounts
Hashtags
Locations
Instagram Lite
Contact Uploading & Non-Users
</div>
<div>
Dance
Food & Drink
Home & Garden
Music
Visual Arts
</div>
<div>
English
© 2022 Instagram from Meta
</div>
</footer>
</section>
If both of your items inside the container are each 50% width, they won't move horizontally—they're spanning across the entire container; there's no free space (and justify-content works by distributing free space).
Remove the width: 50% rule and work on each item individually (using width, margin and/or flex properties).
Also, the justify-content property doesn't take left and right values. They're invalid. Here are the values that work.
Finally, when you're ready to pin both items to the left, consider flex auto margins.
Related
I have created on dashboard page which using css style
But i want to make logout button in top right corner using css like this image using css
How can we do that logout button in right corner top using css?
I tried to do that but it did not happen
CSS:
.dashboard {
height: 100vh;
width: 100vw;
/* display: flex; */
align-items: center;
justify-content: center;
}
.dashboard__container {
display: flex;
flex-direction: column;
text-align: center;
background-color: #dcdcdc;
padding: 30px;
height: 100vh;
width: 100vw;
}
.dashboard__btn {
padding: 10px;
font-size: 18px;
margin-top: 10px;
border: none;
color: white;
background-color: black;
}
.dashboard div {
margin-top: 7px;
}
the html render code
return (
<div className="dashboard">
<div className="dashboard__container">
welcome
<div>{name}</div>
<div>{user?.email}</div>
<button className="dashboard__btn" onClick={logout}>
Logout
</button>
</div>
</div>
);
I think this might work
.dashboard__btn {
position: absolute;
right: 10px;
padding: 10px;
font-size: 18px;
margin-top: 10px;
border: none;
color: white;
background-color: black;
}
you can do this I am just not sure if it's the best practice, I am also a beginner,
.welcome { position: absolute; } //in css
and
<div className="welcome">welcome</div> //in react
Is this what you want?
Just removed some code which does nothing and added justify-content: space-between; to the dashboard__container and that does the trick
.dashboard {
height: 100vh;
width: 100%;
background: #3e295a;
}
.dashboard__container {
display: flex;
flex-direction: row;
justify-content: space-between;
text-align: left;
background-color: #7015b8;
padding: 1em 20px 1em 20px;
color: white;
font-weight: bold;
}
.dashboard__btn {
margin-top: -5px;
font-size: 18px;
padding: 0.25em 0.5em;
border: none;
color: white;
background-color: #402958;
}
<div class="dashboard">
<div class="dashboard__container">
Welcome
<div>{name}</div>
<div>{user?.email}</div>
<button class="dashboard__btn" onclick="{logout}">
Logout
</button>
</div>
</div>
Tell me if its not working...
I am creating a card that will have an image, a title, and a button taking someone to the URL of the program. Since the title will be dynamically generated by the content, I will have no way of knowing how long the title will actually be. I want my card, specifically the card bottom, to grow to show all the text. What is the best way of achieving this??
.program{
height: 250px;
width: 200px;
background-color: red;
/* display: flex;
felx-direction: column; */
}
.program_top{
width: 100%;
height: 50%;
background-color: purple;
background-image: url('https://images.unsplash.com/photo-1581309638082-877cb8132535?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60');
background-repeat: no-repeat;
background-size: cover;
}
.program_bottom{
width: 100%;
height: 50%;
background-color: rgb(32, 32, 32);
display: flex;
flex-direction: column;
justify-content: space-around;
}
.program_title{
padding: 10px;
color: white;
}
.program_button{
text-align:center;
margin-bottom: 20px;
}
.program_button a {
color: orange;
text-decoration: none;
border: 2px solid orange;
padding: 0 30px;
border-radius: 15px
}
<div class="program">
<div class="program_top">
</div>
<div class="program_bottom">
<div class="program_title">
Security For Small Business asfdasdfasdfasdfasdfasdfasdfasdfsdfasdfasdfasdfasdfasdf
</div>
<div class="program_button">
View Program
</div>
</div>
</div>
Here is a codepen for it:
codepen
I changed your CSS to accomplish your needs. Please let me know if you need any additional help.
CSS
.program{
height: auto;
width: 200px;
background-color: red;
display: flex;
flex-direction: column;
}
.program_top{
width: 100%;
height: 125px;
background-color: purple;
background-image: url('https://images.unsplash.com/photo-1581309638082-877cb8132535?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60');
background-repeat: no-repeat;
background-size: cover;
}
.program_bottom{
width: 100%;
height: 50%;
background-color: rgb(32, 32, 32);
display: flex;
flex-direction: column;
justify-content: space-around;
}
.program_title{
padding: 10px;
color: white;
}
.program_button{
text-align: center;
margin-bottom: 20px;
}
.program_button a {
color: orange;
text-decoration: none;
border: 2px solid orange;
padding: 0 30px;
border-radius: 15px
}
On option is to fix the height and basically hide any extra content using
.program_title {
padding: 10px;
color: white;
overflow: hidden;
text-overflow: ellipsis;
}
This helps you to avoid any unexpected layout growth when the info on this container is too big.
The problem is when you need to show all this information, in this case you can provide another way to display the full text (a popup with details, mouseover hint)
.program{
height: 250px;
width: 200px;
background-color: red;
/* display: flex;
felx-direction: column; */
}
.program_top{
width: 100%;
height: 50%;
background-color: purple;
background-image: url('https://images.unsplash.com/photo-1581309638082-877cb8132535?ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60');
background-repeat: no-repeat;
background-size: cover;
}
.program_bottom{
width: 100%;
height: 50%;
background-color: rgb(32, 32, 32);
display: flex;
flex-direction: column;
justify-content: space-around;
}
.program_title {
padding: 10px;
color: white;
overflow: hidden;
text-overflow: ellipsis;
}
.program_button{
text-align:center;
margin-bottom: 20px;
}
.program_button a {
color: orange;
text-decoration: none;
border: 2px solid orange;
padding: 0 30px;
border-radius: 15px
}
<div class="program">
<div class="program_top">
</div>
<div class="program_bottom">
<div class="program_title">
Security For Small Business asfdasdfasdfasdfasdfasdfasdfasdfsdfasdfasdfasdfasdfasdf
</div>
<div class="program_button">
View Program
</div>
</div>
</div>
This question already has answers here:
Understanding z-index stacking order
(1 answer)
Why can't an element with a z-index value cover its child?
(5 answers)
Closed 3 years ago.
attempting to make a simple layout and have hit a dead end. I am trying to make a page that perfectly fits the screen such that there is no scrolling what-so-ever. Basically, in the included code, I'd like to have the reddish title bar (at the top) display on top of the yellowish container. The height of the yellowish container is set to 100vh so as to span the height of the viewport. In this way, the page will be perfectly sized such that you will never need to scroll.
I think it has to do with the z-index...which I thought I understood up until this point. I've watched videos, read articles, and tried everything I could think of. My last resort is trying my luck online.
body,
html {
height: 100%;
margin: 0;
}
.bg {
background-color: rgb(171, 171, 175);
}
header h1 {
text-align: center;
position: relative;
margin: 0;
padding-top: 0.8rem;
background-color: coral;
}
.flex-container {
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.content-box {
border: solid 6px #e7c022;
border-radius: 0.8rem;
height: 45%;
background-color: rgba(128, 128, 128, 0.7);
}
.main-container {
position: relative;
z-index: 1;
height: 100vh;
width: 55vw;
max-width: 700px;
background-color: burlywood;
}
.code-container {
height: 80%;
align-items: center;
}
.key-container {
height: 20%;
align-items: center;
}
.key-code {
font-size: 20rem;
font-family: 'Yellowtail', cursive;
}
.key {
height: 30%;
width: 20%;
border: solid 4px #e7c022;
border-radius: 0.5rem;
text-align: center;
margin-bottom: 3rem;
font-size: 40px;
font-family: 'Share Tech Mono', monospace;
}
.key div {
margin-bottom: 0.2rem;
}
<div class="bg">
<header>
<h1>Titlebar</h1>
</header>
<div class="flex-container main-container">
<div class="content-box">
<div class="flex-container code-container">
<div class="key-code">
<span>65</span>
</div>
</div>
<div class="flex-container key-container">
<div class="flex-container key">
<div>a</div>
</div>
</div>
</div>
</div>
</div>
Do this if you want you navbar to always stick at the top.
body,
html {
height: 100%;
margin: 0;
}
.bg {
background-color: rgb(171, 171, 175);
}
header {
z-index: 11;
position: fixed;
width:100%
}
header h1 {
text-align: center;
position: relative;
margin: 0;
padding-top: 0.8rem;
background-color: coral;
}
.flex-container {
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.content-box {
border: solid 6px #e7c022;
border-radius: 0.8rem;
height: 45%;
background-color: rgba(128, 128, 128, 0.7);
}
.main-container {
position: relative;
z-index: 1;
height: 100vh;
width: 55vw;
max-width: 700px;
background-color: burlywood;
}
.code-container {
height: 80%;
align-items: center;
}
.key-container {
height: 20%;
align-items: center;
}
.key-code {
font-size: 20rem;
font-family: 'Yellowtail', cursive;
}
.key {
height: 30%;
width: 20%;
border: solid 4px #e7c022;
border-radius: 0.5rem;
text-align: center;
margin-bottom: 3rem;
font-size: 40px;
font-family: 'Share Tech Mono', monospace;
}
.key div {
margin-bottom: 0.2rem;
}
<div class="bg">
<header>
<h1>Titlebar</h1>
</header>
<div class="flex-container main-container">
<div class="content-box">
<div class="flex-container code-container">
<div class="key-code">
<span>65</span>
</div>
</div>
<div class="flex-container key-container">
<div class="flex-container key">
<div>a</div>
</div>
</div>
</div>
</div>
</div>
Welcome to SO!
Using position relative with z-index solved the issue on header
When you set position: relative on an element then you establish a new
containing block. All positioning inside that block is with respect to
it.
Setting z-index on an element inside that block will only alter its
layer with respect to other elements inside the same block.
body,
html {
height: 100%;
margin: 0;
}
.bg {
background-color: rgb(171, 171, 175);
}
header {
z-index: 11;
position: relative;
}
header h1 {
text-align: center;
position: relative;
margin: 0;
padding-top: 0.8rem;
background-color: coral;
}
.flex-container {
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
}
.content-box {
border: solid 6px #e7c022;
border-radius: 0.8rem;
height: 45%;
background-color: rgba(128, 128, 128, 0.7);
}
.main-container {
position: relative;
z-index: 1;
height: 100vh;
width: 55vw;
max-width: 700px;
background-color: burlywood;
}
.code-container {
height: 80%;
align-items: center;
}
.key-container {
height: 20%;
align-items: center;
}
.key-code {
font-size: 20rem;
font-family: 'Yellowtail', cursive;
}
.key {
height: 30%;
width: 20%;
border: solid 4px #e7c022;
border-radius: 0.5rem;
text-align: center;
margin-bottom: 3rem;
font-size: 40px;
font-family: 'Share Tech Mono', monospace;
}
.key div {
margin-bottom: 0.2rem;
}
<div class="bg">
<header>
<h1>Titlebar</h1>
</header>
<div class="flex-container main-container">
<div class="content-box">
<div class="flex-container code-container">
<div class="key-code">
<span>65</span>
</div>
</div>
<div class="flex-container key-container">
<div class="flex-container key">
<div>a</div>
</div>
</div>
</div>
</div>
</div>
You need to set z-index for header. Ex:
header{
position: relative;
z-index: 9999
}
If you need your header should stick at the top of the screen. add positioning. ex:
header{
position: fixed;
top: 0;
width: 100%;
z-index: 9999
}
Hope someone can shed light on this question of mine.
I have a flex container, which has 2 flex containers with flex-direction: column.
However, it all displays in 1 column.
Initially, it displayed in 2 columns but did not start at the same height, and now it is in one column only.
Advise here will be appreciated.
<!-- ***** finding container ***** -->
section.finding-container {
top: 180px;
display: flex;
flex-direction: row;
position: absolute;
justify-content: space-between;
align-items: center;
/* height: 100% */
/* margin-right: 215px; */
}
.find-agent {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 350px;
margin-bottom: auto;
margin-left: 50px;
}
.find-agent img,
h1,
p,
button {
display: block;
margin-left: auto;
margin-right: auto;
}
.find-agent h1 {
font-weight: 550;
color: #1E95EE;
text-align: center;
margin-top: 12px;
margin-bottom: 0;
}
.find-agent p {
color: #3A3C3E;
font-weight: 350;
width: 445px;
height: 71px;
text-align: center;
opacity: 1;
}
.try {
border: 2px solid #1E95EE;
border-radius: 5px;
opacity: 1;
color: #1E95EE;
font-size: 18px;
font-weight: Regular;
height: 50px;
width: 143px;
text-align: center;
vertical-align: middle;
text-decoration: none;
justify-content: center;
}
.agent-profiles {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 0;
margin-bottom: auto;
}
.agent-profiles h2,
img {
display: block;
margin-left: auto;
margin-right: auto;
}
.agent-profiles h2 {
font-weight: 350;
color: #1E95EE;
text-align: center;
width: 182px;
height: 44px;
letter-spacing: 0;
opacity: 1;
}
```
<!-- ***** finding container ***** -->
<section class="finding-container">
<div class="find-agent">
<img src="./images/search.svg" alt="search">
<h1>Find the perfect agent</h1>
<p>
No more browsing through thousands of applications. Each week, we'll send you a fresh batch of hand-picked, personally-vetted candidates.
</p>
<button type="button" class="try">Try today</button>
</div>
<div class="agent-profiles">
<h2>
Selections from the Overpass Marketplace
</h2>
<img src="./images/profiles.svg" alt="profiles">
</div>
</section>
I have a flex container, which has 2 flex containers with flex-direction: column.
You've got an invalid comment in your CSS, which is breaking your first line of code:
<!-- ***** finding container ***** -->
section.finding-container {
top: 180px;
display: flex;
flex-direction: row;
position: absolute;
justify-content:space-between;
align-items: center;
/* height: 100% */
/* margin-right: 215px; */
}
That's HTML commenting syntax. In CSS, it's invalid, so the following section.finding-container selector is seen as an error and ignored. The container then falls back to its default layout model, display: block, which stacks child elements vertically. (You can see the proper CSS commenting syntax at the bottom of your rule.)
More details about CSS commenting syntax and error handling:
Why are some of my CSS rules not working?
Initially, it displayed in 2 columns but did not start at the same height ...
You've got all sorts of margins and alignment properties (such as justify-content) set on the items and container, so they're rendering at different heights.
section.finding-container {
/* top: 180px; */
display: flex;
flex-direction: row;
position: absolute;
justify-content: space-between;
/* align-items: center; */
border: 2px dashed red; /* for illustration purposes */
padding: 10px; /* for illustration purposes */
}
.find-agent {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
/* margin-top: 350px; */
/* margin-bottom: auto; */
/* margin-left: 50px; */
border: 1px solid green; /* for illustration purposes */
}
.find-agent img,
h1,
p,
button {
display: block;
margin-left: auto;
margin-right: auto;
}
.find-agent h1 {
font-weight: 550;
color: #1E95EE;
text-align: center;
margin-top: 12px;
margin-bottom: 0;
}
.find-agent p {
color: #3A3C3E;
font-weight: 350;
width: 445px;
height: 71px;
text-align: center;
opacity: 1;
}
.try {
border: 2px solid #1E95EE;
border-radius: 5px;
opacity: 1;
color: #1E95EE;
font-size: 18px;
font-weight: Regular;
height: 50px;
width: 143px;
text-align: center;
vertical-align: middle;
text-decoration: none;
justify-content: center;
}
.agent-profiles {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 0;
/* margin-bottom: auto; */
border: 1px solid black; /* for illustration purposes */
}
.agent-profiles h2,
img {
display: block;
margin-left: auto;
margin-right: auto;
}
.agent-profiles h2 {
font-weight: 350;
color: #1E95EE;
text-align: center;
width: 182px;
height: 44px;
letter-spacing: 0;
opacity: 1;
}
<section class="finding-container">
<div class="find-agent">
<img src="./images/search.svg" alt="search">
<h1>Find the perfect agent</h1>
<p>
No more browsing through thousands of applications.
Each week, we'll send you a fresh batch of hand-picked,
personally-vetted candidates.
</p>
<button type="button" class="try">Try today</button>
</div>
<div class="agent-profiles">
<h2>
Selections from the
Overpass Marketplace
</h2>
<img src="./images/profiles.svg" alt="profiles">
</div>
</section>
I know this is probably a basic question but so far I have not been able to resolve it via google:
I want to have a navbar with an Image (a logo) and 3 links on its right. I want them all to have the same height and to be on the same height, a little bit like this:
however all I manage is to make it look like this:
#nav-bar {
position: fixed;
top: 0px;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
}
#flex {
display: flex;
justify-content: start;
flex-wrap: wrap;
align-content: center;
}
img {
margin-top: 20px;
height: auto;
width: 15%;
}
.nav-link {
border: 1px solid #4c4c4c;
padding: 0.5em;
background-color: #b7b7b7;
color: black;
text-decoration: none;
}
<nav id="nav-bar">
<div id="flex">
<div><img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img"></div>
Products
Demo
Newsletter
</div>
</nav>
Maybe something like this:
#nav-bar {
position: fixed;
top: 0px;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
}
#flex{
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-content: center;
}
img {
height: 50px;
width: auto;
}
.nav-links {
padding-right: 50px;
}
.nav-links .nav-link {
border: 1px solid #4c4c4c;
background-color: #b7b7b7;
color: black;
height: 50px;
display: inline-block;
text-decoration: none;
}
<nav id="nav-bar">
<div id="flex">
<img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img">
<div class="nav-links">
Products
Demo
Newsletter
</div>
</div>
</nav>
Just wrap links into a div, then set justify-content to 'space-between' and set the same height of both image and div with links. Hope it will help
You almost did it, the only thing you needed was basically to size the <div> around the <img> appropriately, so the <img> could just fill it:
#nav-bar {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
box-sizing: border-box; /* to exclude paddings&borders from width instead of adding them */
}
#flex{
display: flex;
justify-content: start;
align-items: stretch;
}
/* sizing the div with the img */
#flex > div {
width: 15%;
flex: 1 0 auto;
}
/* making the img filling this div */
img{
display: block;
width: 100%;
}
.nav-link{
border: 1px solid #4c4c4c;
padding: 0.5em;
background-color: #b7b7b7;
color: black;
text-decoration: none;
/* making links fill all the space, except some gaps between them */
flex: 1 1 auto;
margin-left: .5em;
/* centering the text in the links and making it responsive */
display: flex;
justify-content: center;
align-items: center;
font-size: calc(10px + 2vw);
}
<nav id="nav-bar">
<div id="flex">
<div>
<img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img">
</div>
Products
Demo
Newsletter
</div>
</nav>