So, right now my header doesn´t look good on mobile. - The words overlap. They should remain in the same order... I tried to use line-height, which did not really change anything. Maybe you have some suggestions on how I can fix this problem. I am thankful for every suggestion!
[enter
.header {
width: 100%;
height: 7vh;
padding: 0 5%;
color: white;
font-size: larger;
background-color: black;
z-index:100;
position: sticky;
top: 0;
display: flex;
justify-content: space-between;
overflow: hidden;
line-height: 10px;
}
nav {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 4px 0;
}
nav ul li {
display: inline-block;
list-style: none;
margin: 10px 30px;
}
nav ul li a {
text-decoration: none;
color: white;
}
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.Menü {
color: white;
text-decoration: none;
margin-left: 40px;
}
<div class="header" >
<nav>
<div>
<Button class="ImageButton"> <input class="ImageButton" type="image" src="/Images/Camellion Logo Website.png"></Button>
</div>
<ul>
<a class="Menü" href="/Galerie/Galerie.html">Galerie</a>
<a class="Menü" href="#Leistungen">Leistungen</a>
<a class="Menü" href="#Kontakt">Kontakt & Standort <i class="fa-solid fa-location-dot"></i></a>
</ul>
</nav>
</div>
There is a thing in CSS called media queries. With media queries you can write for example CSS that only takes effect if screen is certain size.
For example
#media only screen and (min-width: 360px) and (max-width: 800px) {
.header {
height: 60px;
}
}
Will set header height to 60px if the device that the page is opened on has screen width more then 360px and less then 800px.
Here is your code with couple adjustments
* { padding: 0; margin: 0; box-sizing: border-box; }
.header {
width: 100%;
padding: 0 20px;
color: white;
background-color: black;
position: sticky;
z-index:100;
top: 0;
}
.navigation {
margin: auto;
max-width: 1200px;
height: 80px;
display: flex;
align-items: center;
justify-content: space-between;
}
.menu-icon { /* CSS to just to simulate Icon */
height: 40px;
width: 40px;
background-color: white;
border-radius: 10px;
}
.menu {
display: flex;
align-items: center;
gap: 40px;
}
.menu-item {
color: white;
text-decoration: none;
white-space: nowrap; /* Will not let words to break to next line */
font-size: 20px;
font-weight: 700;
}
#media(max-width: 600px) {
.header { padding: 0 10px; }
.navigation { height: 60px; }
.menu { gap: 20px;}
.menu-item { font-size: 14px; }
}
#media(max-width: 400px) {
.menu { gap: 10px;}
.menu-item { font-size: 12px; }
}
<header class="header" >
<nav class="navigation">
<div class="menu-icon" title="Menu icon / hamburger icon"></div>
<div class="menu">
<a class="menu-item" href="/Galerie/Galerie.html">Galerie</a>
<a class="menu-item" href="#Leistungen">Leistungen</a>
<a class="menu-item" href="#Kontakt">Kontakt & Standort <i class="fa-solid fa-location-dot"></i></a>
</div>
</nav>
</header>
You can adjust your css even further. It's very popular to have icons with menu elements and on mobile view they become a bottom navigation bar with big icons and tiny text.
#media (max-width:767px) {
* {
box-sizing: border-box;
}
nav {
flex-direction: column;
}
nav .Menu {
margin-inline: 9px
}
}
good luck
Im working on the product landing page project from freecodecamp, and I'm struggling to understand what I'm not doing right with my flexbox nav bar.
My nav links start to disappear off the right side as the viewport width shrinks below 1200px.
What can I do to maintain padding-right: 5px; value on the right hand most nav item as the viewport changes size?
here is my HTML and CSS, as well as the codepen link https://codepen.io/lforsey/pen/NWwGZzV
<div id='page-wrapper'>
<header id='header'>
<div class='cat-logo'>
<img id='header-img' src='https://free-images.com/or/7b03/logo_hoffmanns_staerkefabriken_svg.svg' id='cat-logo' alt='cat-svg-logo'></img>
</div>
<nav id='nav-bar'>
<ul>
<li><a class='nav-link' href='#features' id='nav-link'>Features</a></li>
<li><a class='nav-link' href='#how-it-works' id='nav-link'>How It Works</a></li>
<li><a class='nav-link' href='#pricing' id='nav-link'>Pricing</a></li>
</ul>
</nav>
</header>
<div class='container'></div>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#page-wrapper {
position: relative;
}
.container {
max-width: 1000px;
width: 100%;
margin: 0 auto;
}
.grid {
display: flex;
}
header {
position: fixed;
top: 0;
min-height: 75px;
padding: auto;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #eee;
}
/*header {
display: flex;
flex: 0 0 auto;
top: 0;
left: 0;
right: 0;
}*/
.logo {
width: 60vw;
}
#media (max-width: 650px) {
.logo {
margin-top: 15px;
width: 100%;
position: relative;
}
}
.cat-logo > img {
width: 100%;
height: 100%;
width: 100px;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.nav-bar {
display: flex;
flex-direction: row;
justify-content: space-between;
}
li {
font-family: cursive;
list-style: none;
padding: 1vw;
}
nav > ul {
width: 95vw;
display: flex;
content-align: center;
flex-direction: row;
justify-content: flex-end;
padding-right: 20px;
}
Take away your line 70 :
70: width: 95vw;
And it will works.
So on my mobile view, I want the banner to show my mobile image and I was alternating the display properties in the media query. This is my first question on Stack, sorry if I omitted something.
<div class="row">
<div class="image-container">
<img class="desktopimage" src="../resources/images/indeximage.jpg" alt="">
<img class="mobileimage" src="../resources/images/mobileindeximage.jpg" alt="">
</div>
<div class="intro-container">
<div class="intro">
<h2>Work hard today, Be Lean tomorrow.</h2>
<h4></h4>
<p></p>
</div>
</div>
</div>
Then here I have the scss for it, the DevTools in the browser crosses off the **display:block** property in the media query.
.banner {
display: flex;
width: 100%;
flex-direction: column;
position: relative;
.row {
display: flex;
width: 100%;
flex-direction: row;
align-items: center;
justify-content: flex-end;
.image-container {
min-width: 100%;
.desktopimage {
width: 100%;
height: 95vh;
}
.mobileimage {
display: none;
width: 100%;
height: 100vh;
}
}
.intro-container {
display: flex;
justify-content: center;
background-color: rgb(255, 255, 255);
position: absolute;
border-radius: 20px;
opacity: 0.9;
right: 1rem;
.intro {
text-align: center;
opacity: 0.9;
padding: 1em;
color: rgb(7, 6, 6);
h2 {
font-family: 'Permanent Marker', cursive;
color: rgb(0, 0, 0);
}
}
}
}
}
#media (max-width: 900px) {
.desktopimage {
display: none;
}
.mobileimage {
display: block;
}
}
You need to add .banner .row .image-container in the selector (i.e. the elements into which your two classes are nested in your sass code) to achieve at least the same level of CSS specifity as for the default styles:
#media (max-width: 900px) {
.banner .row .image-container {
.desktopimage {
display: none;
}
.mobileimage {
display: block;
}
}
}
I'm trying to implement the following responsive behaviour for a navbar.
Here is the result I want on large screens:
And on small screens (Iphone 8 and similar):
I created the navbar using flexbox and the possible solution I have in mind is using flex-wrap: wrap; but I need to find a way to only make the two links (with tmp class) go down when the screen is small and keep the logo and the "S'inscrire" link up when the screen is small.
I'm not sure if flexbox is the best way to achieve that but it's what I tried, I'm open to any better solution.
.navigation {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.navigation__items {
display: flex;
justify-content: space-between;
}
.tmp {}
.navigation__item {
list-style: none;
}
.navigation__item a {
text-decoration: none;
color: inherit;
padding: 11px 40px;
}
.navigation__item a:active {
text-decoration: none;
color: #0065fc;
font-weight: bold;
border-top: 2px solid #0065fc;
}
.subscribe {
color: #0065fc;
font-weight: bold;
}
#media only screen and (max-width: 500px) {
.navigation__items {
margin-top: 25px;
width: 100%;
}
}
<nav class="navigation">
<img src="./assets/images/logo/Reservia.svg" alt="Logo Reservia" />
<ul class="navigation__items">
<div class="tmp">
<li class="navigation__item">Hébergements</li>
<li class="navigation__item">Activités</li>
</div>
<li class="navigation__item subscribe">
S'inscrire
</li>
</ul>
</nav>
PS: the div with "tmp" class doesn't originally exist in the code, I added it just to indicate the idea I have in mind.
Pay attention to your html structure of the <ul> tag. Inside you put the <div> tag, separating the third <li> tag from the first two. This is not correct and it is not a valid html structure. It's a crutch.
In my example, I set up the list structure correctly. All three <li> tags are now children of the <ul> tag.
Now about the main thing.
The very principle of the transfer of the third <li> tag (subscribe class) is based on absolute positioning.
Wrapping the first two <li> tags is triggered at 767px width.
And yet, in my example, I did not use other types of display, such as grid, table, block, etc. Only flex is used.
Also, the underline on click is adjusted.
.navigation {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.navigation img { /*for test*/
width: 100px;
}
.navigation__items {
display: flex;
justify-content: space-between;
padding: 0;
}
.navigation__item {
list-style: none;
}
.navigation__item a {
text-decoration: none;
color: inherit;
padding: 11px 40px;
}
.navigation__item a:active {
text-decoration: none;
color: #0065fc;
font-weight: bold;
border-top: 2px solid #0065fc;
}
.subscribe {
color: #0065fc;
font-weight: bold;
}
#media (max-width: 500px) {
.navigation__items {
margin-top: 25px;
/*width: 100%;*/
}
}
#media (max-width: 767px) {
.navigation {
position: relative;
}
.navigation__items {
width: 100%;
}
.navigation__item a {
display: flex;
justify-content: center;
padding: 11px 0;
}
.navigation__item {
flex: auto;
text-align: center;
}
.navigation__item.subscribe {
position: absolute;
top: 0;
right: 0;
}
.navigation__item a:active {
border-top: unset;
border-bottom: 2px solid #0065fc;
}
}
<nav class="navigation">
<img src="https://i.ibb.co/LDTTHj3/2021-01-18-13-00-56.png" alt="Logo Reservia" />
<ul class="navigation__items">
<li class="navigation__item">Hébergements</li>
<li class="navigation__item">Activités</li>
<li class="navigation__item subscribe">S'inscrire</li>
</ul>
</nav>
So, this is the layout and how things could be grouped, right? (small-screen-first of course)
You can totally do this with grid as well - but here's how I'd do it with flex-box;
you can use flex's order
and A few margin: autos in there.
https://codepen.io/sheriffderek/pen/a16a64f1910cbd05116dd1a9ae37a372?editors=1100
/* reset included */
* {
box-sizing: border-box;
}
header {
/* probably has a column in it */
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.logo {
display: block;
}
.thing {
display: block;
margin-left: auto; /* trick */
}
.site-menu {
width: 100%;
display: flex;
flex-direction: row;
}
.link {
display: block;
flex-basis: 50%;
}
#media (min-width: 600px) {
header {
justify-content: flex-end;
}
.logo {
margin-right: auto; /* trick */
}
.thing {
order: 5;
margin-left: unset; /* override */
}
.site-menu {
width: auto;
}
}
header {
border: 4px solid dodgerblue;
}
.logo {
border: 4px solid orange;
padding: 10px;
}
.thing {
border: 4px solid yellow;
padding: 10px;
}
.site-menu {
border: 4px solid lime;
}
.link {
border: 4px solid #ff0066;
padding: 10px;
}
<header>
<a class='logo'>
SVG LOGO
</a>
<a class='thing'>
thing
</a>
<nav class='site-menu'>
<a class='link'>
link 1
</a>
<a class='link'>
link 2
</a>
</nav>
</header>
Possible Solution:
Change position and layout properties
In mobile, I've changed the parent navigation element's display and position property to block and relative.As a result, the banner and navigation__items element would not come under flexbox modal.
Now we want the temp element to take 100% width, for this, I've changed the flex property to 0 0 100%.
To show the 'subscribe' button on the top right corner, add its position property to absolute.
.navigation {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.navigation__items {
display: flex;
justify-content: space-between;
flex-wrap: nowrap;
padding: 0;
}
.tmp {
display: flex;
flex-wrap: nowrap;
}
.tmp .navigation__item {
flex: 0 0 50%;
}
.navigation__item {
list-style: none;
}
.navigation__item a {
text-decoration: none;
color: inherit;
padding: 11px 40px;
}
.navigation__item a:active {
text-decoration: none;
color: #0065fc;
font-weight: bold;
border-top: 2px solid #0065fc;
}
.subscribe {
color: #0065fc;
font-weight: bold;
}
#media screen and (max-width: 767.98px) {
.navigation {
display: block;
position: relative;
}
.tmp {
flex: 0 0 100%;
}
.subscribe {
position: absolute;
top: 0;
right: 0;
}
}
<nav class="navigation">
<img src="./assets/images/logo/Reservia.svg" alt="Logo Reservia" />
<ul class="navigation__items">
<div class="tmp">
<li class="navigation__item">Hébergements</li>
<li class="navigation__item">Activités</li>
</div>
<li class="navigation__item subscribe">
S'inscrire
</li>
</ul>
</nav>
Just add flex-direction: column-reverse; to .navigation__items class in media queries:
#media only screen and (max-width: 500px) {
.navigation__items {
flex-direction: column-reverse;
}
}
Codepen: https://codepen.io/manaskhandelwal1/pen/rNMqpoY?editors=1100
I recommend using CSS grid, it is easy, and you can specify, when content should wrap to next line...
nav {
display: grid;
grid-template-rows: auto;
/* aligning and more stuff... */
}
#media only screen and (max-width: 800px) {
nav {
grid-template-rows: auto auto;
}
}
More information about grids here: https://www.w3schools.com/css/css_grid.asp
I recommend using the position property. Try the code below
.navigation {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
/* Add position to the parent element so the position of tmp class falls to this parent*/
position: relative;
}
/* ... code ... */
/*
Add this code in the media query. Giving .tmp a position property will pull it out of the flex box, meaning flex box won't have an effect on it
*/
.tmp {
/* Make this class position absolute Think of it as absolute to the navigation div */
position: absolute;
/* Position it -20px or something below the navigation div. You can play around with this. */
bottom: -20px
/* left from 50% of the navigation tag */
left: 50%;
/* Pull it back by 50% of its own size on x-axis to center it perfectly */
transform: translateX(-50%);
}
You need the transform property to center it, Otherwise it will be 50% off the screen. Hope this helps 🙂
Tell me this works pal ,
* {
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}
header {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.logo {
display: block;
}
.thing {
display: block;
margin-left: auto; /* trick */
}
.site-menu {
width: 100%;
display: flex;
flex-direction: row;
}
.link {
display: block;
flex-basis: 50%;
}
#media (min-width: 600px) {
header {
justify-content: flex-end;
}
.logo {
margin-right: auto; /* trick */
}
.thing {
order: 5;
margin-left: unset; /* override */
}
.site-menu {
width: auto;
}
}
.thing {
display: block;
margin-left: auto; /* trick */
}
.logo {
border: 4px solid orange;
padding: 10px;
}
.link {
padding: 10px;
text-align: center;
border-top: 4px solid transparent;
}
.link:active {
border-top: 4px solid #007cff;
padding: 10px;
}
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#300&display=swap" rel="stylesheet">
<header>
<a class='logo' >
Fancy Text
</a>
<a class='thing' >
thing
</a>
<nav class='site-menu'>
<a class='link' >
link 1
</a>
<a class='link' >
link 2
</a>
</nav>
</header>
There are a few methods to answer your question, but first let me suggest something.
Please reformat your html
You have a div in your ul.
The div cuts the ul as 2 lis come within it while 1 is placed outside it. This is not valid HTML. Your elements should be positioned in a proper hierarchy.
Nevertheless here’s the code you need:
.navigation {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.navigation img {
width: 100px;
}
.navigation-items {
display: flex;
justify-content: space-between;
padding: 0;
}
.navigation-item {
list-style: none;
}
.navigation-item a {
text-decoration: none;
color: inherit;
padding: 11px 40px;
}
.navigation-item a:hover {
text-decoration: none;
color: #0065fc;
font-weight: bold;
border-top: 2px solid #0065fc;
}
.subscribe {
color: #0065fc;
font-weight: bold;
}
#media (max-width: 600px) {
.navigation-items {
margin-top: 25px;
/*width: 100%;*/
}
}
#media (max-width: 700px) {
.navigation {
position: relative;
}
.navigation-items {
width: 100%;
}
.navigation-item a {
display: flex;
justify-content: center;
padding: 11px 0;
}
.navigation-item {
flex: auto;
text-align: center;
}
.navigation-item.subscribe {
position: absolute;
top: 0;
right: 0;
}
.navigation-item a:active {
border-top: unset;
border-bottom: 2px solid #0065fc;
}
}
<nav class="navigation">
<img src="https://i.ibb.co/LDTTHj3/2021-01-18-13-00-56.png" alt="Logo Reservia" />
<ul class="navigation-items">
<li class="navigation-item"><u>Hébergements</u></li>
<li class="navigation-item"><u>Activités</u></li>
<li class="navigation-item subscribe"><u>S'inscrire</u></li>
</ul>
</nav>
I have created a solution using flexbox as you wanted - HTML is also simplified - 'tmp' container no longer required.
.navigation {
display: flex;
align-items: center;
}
.navigation__items {
display: flex;
margin-left:auto;
}
.navigation__item {
list-style: none;
}
.navigation__item a {
text-decoration: none;
color: inherit;
padding: 11px 40px;
}
.navigation__item a:active {
text-decoration: none;
color: #0065fc;
font-weight: bold;
border-top: 2px solid #0065fc;
}
.subscribe {
color: #0065fc;
font-weight: bold;
}
#media only screen and (max-width: 500px) {
.navigation {
flex-wrap:wrap;
}
.navigation__items {
margin-top: 25px;
width: 100%;
order:3;
}
.navigation__items li {
width:50%;
}
.navigation__items_alt {
margin-left:auto;
order:2;
}
}
<nav class="navigation">
<img src="./assets/images/logo/Reservia.svg" alt="Logo Reservia" />
<ul class="navigation__items">
<li class="navigation__item">Hébergements</li>
<li class="navigation__item">Activités</li>
</ul>
<ul class="navigation__items_alt">
<li class="navigation__item subscribe">
S'inscrire
</li>
</ul>
</nav>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
width: 100%;
}
a{
text-decoration: none;
color: #0065fc;
}
.header{
margin:auto;
width:90%;
display: flex;
height: 4rem;
justify-content: space-between;
}
.logo{
display: inline-flex;
vertical-align: middle;
font-size: 2rem;
}
.logo img{
padding:.25rem;
height: 4rem;
justify-content: center;
}
.nav{
display: inline-flex;
flex-direction: row-reverse;
}
ul{
display: inline-flex;
margin-right: 0;
list-style:none;
}
ul li a{
text-decoration: none;
display: inline-flex;
padding-left: 2.5rem;
padding-right: 2.5rem;
line-height:4rem ;
margin-right: 0;
border-top: 2px solid #0065fc;
}
#media only screen and (max-width: 800px) {
.nav2{
display: flex;
width: 100%;
position: absolute;
margin-top: 4rem;
justify-content:space-evenly;
}
.nav2 li a{
border-top: none;
border-bottom: 2px solid #0065fc;
}
}
<div class="header">
<div class="logo">
Reservia
</div>
<div class="nav">
<ul>
<li>S'inscrire</li>
</ul>
<ul class="nav2">
<li>Hébergements</li>
<li>Activités</li>
</ul>
</div>
</div>
Steps to think:
Breaking One Menu to Two Lists
Rearranging second list using media query.
I hope this helps. Only flex is used. No Grid
You can try code below. its all about structuring your html code and using flexbox.
Change or adjust css properties according to your code. I hope this helps you. Good luck.
/* `XHTML, HTML4, HTML5 Reset
-------------------------------*/
a,b,body,div,li,nav,ol,span,ul{border:0;margin:0;padding:0;font-size:100%}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}body,html{font-family:'Open Sans',sans-serif;font-size:15px;font-weight:400;height:100%;background-color:#f7f7f7;color:#212121}nav{display:block}ol,ul{list-style:none}li{display:list-item}a{color:inherit;text-decoration:none}button{font-family:'Open Sans',sans-serif;border:0;margin:0;padding:0;outline:0}
/*main css starts*/
.mainNav {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-items: center;
}
.navItems {
display: flex;
width: 100%;
margin-top: 15px;
}
.navItems > li {
width: 50%;
text-align: center;
}
.mainNav .logo {
font-family: cursive;
font-size: 2.5em;
font-weight: bold;
color: #0065fc;
}
#media (min-width: 768px) {
.mainNav {
align-items: baseline;
}
.mainNav .subs {
order: 3;
padding: 5px 15px;
}
.mainNav .logo {
flex: 1;
}
.navItems {
width: auto;
}
.navItems > li {
width: auto;
padding: 5px 15px;
}
}
<nav class="mainNav">
<a class="logo" href="#">Reservia</a>
<a class="subs" href="#">S'inscrire</a>
<ul class="navItems">
<li>Hébergements</li>
<li>Activités</li>
</ul>
</nav>
Grid is often more powerful than flexbox for non-trivial layouts where it allows you to achieve the same result with less code and without redundant wrapper elements.
Your problem could be solved reasonably with flexbox, but why not challenge the assumption of the question and do it using grid, perhaps it will fit you better. Here is a super clean and simple grid solution:
I started with restructuring your HTML:
<nav>
<img alt="Logo Reservica"/>
<a>S'inscrire</a>
<ul>
<li><a>Hébergements</a></li>
<li><a>Activités</a></li>
</ul>
</nav>
Then I created a grid with 2 columns:
nav {
display: grid;
grid-template-columns: 1fr auto;
}
This puts the img and a into the 1. and 2. column of the 1. row, and the ul ends up in the 1. column of the 2. row. We stretch the ul over both columns and the core of the mobile layout is done:
ul {
grid-column: 1/3;
}
To make this work for desktop, we change the grid to have 3 columns. Then we move the ul to the 2. column of the 1. row. That's it!
#media (min-width: 600px) {
nav {
grid-template-columns: 1fr auto auto;
}
ul {
grid-row: 1;
grid-column: 2;
}
}
Here is a working example:
nav {
display: grid;
grid-template-columns: 1fr auto;
}
ul {
margin: 0;
padding: 0;
list-style-type: none;
grid-column: 1/3;
display: flex;
justify-content: space-evenly;
}
#media (min-width: 600px) {
nav {
grid-template-columns: 1fr auto auto;
}
ul {
grid-row: 1;
grid-column: 2;
}
li {
padding-right: 20px;
}
}
<nav>
<img alt="Logo Reservica"/>
<a>S'inscrire</a>
<ul>
<li><a>Hébergements</a></li>
<li><a>Activités</a></li>
</ul>
</nav>
I intentionally use bare HTML with minimal styling in the example to not distract you from the actual solution. If you want to understand grid better, MDN is a great resource: https://developer.mozilla.org/en-US/docs/Web/CSS/grid
.flex-container {
}
.flex-container-left > div {
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
float:left;
}
.flex-container-right > div {
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
float:right;
}
.flex-container-left .bottom{
float:right;
}
#media only screen and (max-width: 500px) {
.flex-container {
display: flex;
flex-direction: column;
width: 100%;
}
.flex-container-right{
width:100%;
}
}
<div class="flex-container">
<div class="flex-container-left">
<div>1</div>
<div class="bottom">4</div>
</div>
<div class="flex-container-right">
<div>3</div>
<div>2</div>
</div>
</div>
Here is the screenshot of Desktop view :
500px width screen size view :
.navigation {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.navigation img {
width: 100px;
}
.navigation__items {
display: flex;
justify-content: space-between;
padding: 0;
}
.navigation__item {
list-style: none;
}
.navigation__item a {
text-decoration: none;
color: inherit;
padding: 11px 40px;
}
.subscribe {
color: #0065fc;
font-weight: bold;
}
#media (max-width: 500px) {
.navigation__items {
margin-top: 25px;
/*width: 100%;*/
}
}
#media (max-width: 767px) {
.navigation {
position: relative;
}
.navigation__items {
width: 100%;
}
.navigation__item a {
display: flex;
justify-content: center;
padding: 11px 0;
}
.navigation__item {
flex: auto;
text-align: center;
}
.navigation__item.subscribe {
position: absolute;
top: 0;
right: 0;
}
.navigation__item .active {
text-decoration: none;
color: #0065fc;
font-weight: bold;
border-bottom: 2px solid #0065fc;
}
}
#media(min-width: 768px){
.navigation__item .active {
text-decoration: none;
color: #0065fc;
font-weight: bold;
border-top: 2px solid #0065fc;
}
}
<nav class="navigation">
<img src="https://i.ibb.co/LDTTHj3/2021-01-18-13-00-56.png" alt="Logo Reservia" />
<ul class="navigation__items">
<li class="navigation__item"><a class="active" href="#">Hébergements</a></li>
<li class="navigation__item">Activités</li>
<li class="navigation__item subscribe">S'inscrire</li>
</ul>
</nav>
I would like to thank scooterlord
I had done the source code by his help. Here his answer on this post
I hope this source code would help you.
Desktop View :
Android View :
I have this navigation bar that works really well. It is fixed so it follows you as you scroll through the website. However, I would like for the navbar to only start in the second section (#home) and for it to not be visible in the first section (#section0).
Could I please have some help?
#section0 {
width: 100%;
height: 100vh;
background-color: blue;
}
#home {
width: 100%;
height: 100vh;
background-color: white;
display: block;
margin: 0 auto;
}
#home ul {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
z-index: 9999;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
position: -webkit-fixed;
/* Safari */
position: fixed;
top: 0;
}
#home ul li.left-menu {
display: flex;
justify-content: flex-end;
}
#home ul li.right-menu {
display: flex;
justify-content: flex-start;
}
#home li a {
display: block;
color: white;
text-align: center;
padding: 13px 20px;
text-decoration: none;
font-family: Futura;
font-size: 8px;
}
#home li a:hover {
color: #00CFFF;
}
#home .active {
color: #00CFFF;
}
#secondpage {
height: 100vh;
width: 100%;
background-color: orange;
}
<section id="section0">
</section>
<section id="home">
<ul>
<li class="left-menu">
<a class="active" href="#home">HOME</a>
HOW IT WORKS
WHY CHOOSE US
</li>
</li>
<li class="right-menu">
SERVICES
OUR GALLERY
CONTACT US
</li>
</section>
<section id="secondpage">
</section>
Just set a higher z-index for the first section.
body {
margin: 0;
padding: 0;
}
#section0 {
width: 100%;
height: 100vh;
background-color: blue;
z-index: 99999;
position: relative;
}
#home {
width: 100%;
height: 100vh;
background-color: white;
display: block;
margin: 0 auto;
}
#home ul {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
z-index: 9999;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
position: -webkit-fixed;
/* Safari */
position: fixed;
top: 0;
}
#home ul li.left-menu {
display: flex;
justify-content: flex-end;
}
#home ul li.right-menu {
display: flex;
justify-content: flex-start;
}
#home li a {
display: block;
color: white;
text-align: center;
padding: 13px 20px;
text-decoration: none;
font-family: Futura;
font-size: 8px;
}
#home li a:hover {
color: #00CFFF;
}
#home .active {
color: #00CFFF;
}
#secondpage {
height: 100vh;
width: 100%;
background-color: orange;
}
<section id="section0">
</section>
<section id="home">
<ul>
<li class="left-menu">
<a class="active" href="#home">HOME</a>
HOW IT WORKS
WHY CHOOSE US
</li>
</li>
<li class="right-menu">
SERVICES
OUR GALLERY
CONTACT US
</li>
</section>
<section id="secondpage">
</section>
Note:
I have added position: relative to first section (.section0) for z-index to work.
I have remove margin and padding from <body> only to make this snippet clean.
Edit: As you said, the previous example makes the navigation bar slide out from under the first section, you can try this example using position: sticky.
I'll explain what I did here.
I took the navigation bar (<ul>) out of home section.
I have wrapped the element <ul>, home and secondpage in an element and gave it a class called wrapper.
The first section remains out of the wrapper.
I have applied position: sticky; to navigation (<ul>) and added a top value at which the navigation should stay fixed.
I have also added position: relative; to wrapper class for the sticky element to work.
This means the navigation bar (<ul>) stays fixed inside the wrapper class.
Working Example:
body {
margin: 0;
padding: 0;
}
#section0 {
width: 100%;
height: 100vh;
background-color: blue;
position: relative;
}
#home {
width: 100%;
height: 100vh;
background-color: white;
display: block;
margin: 0 auto;
}
ul {
background: #fff;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
z-index: 9999;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
position: -webkit-fixed;
/* Safari */
/*position: fixed;*/
position: sticky;
top: 0;
}
ul li.left-menu {
display: flex;
justify-content: flex-end;
}
ul li.right-menu {
display: flex;
justify-content: flex-start;
}
ul li a {
display: block;
color: white;
text-align: center;
padding: 13px 20px;
text-decoration: none;
font-family: Futura;
font-size: 8px;
}
li a:hover {
color: #00CFFF;
}
.active {
color: #00CFFF;
}
#secondpage {
height: 100vh;
width: 100%;
background-color: orange;
}
.wrapper {
position: relative;
}
<section id="section0">
</section>
<div class="wrapper">
<ul>
<li class="left-menu">
<a class="active" href="#home">HOME</a>
HOW IT WORKS
WHY CHOOSE US
</li>
<li class="right-menu">
SERVICES
OUR GALLERY
CONTACT US
</li>
</ul>
<section id="home">
</section>
<section id="secondpage">
</section>
</div>