I am trying to list navigation elements from left to right like this:
Start Über Weitere Kontakt instead of this
Start
Über
Weitere
Kontakt
but it doesn't seem to work. I have already tried using float: left;
,display:inline; and list-style: none; on #navigation li but it just stays the same.
This is the navigation structure in the index.html
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body header {
top: 0;
left: 0;
display: flex;
position: absolute;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 30px 100px;
}
#navigation {
display: flex;
justify-content: center;
align-items: center;
}
#navigation li {
display: inline;
position: absolute;
}
<header>
Logo
<ul class="navigation">
<li>Start</li>
<li>Über</li>
<li>Weitere</li>
<li>Kontakt</li>
</ul>
</header>
You have given ul a class="navigation"
But the problem is that in your CSS you are using the id selector
#navigation
Jsut change it to class selector:
.navigation
Also, to achieve your goal position is not required.
The Following Code is Sufficient.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 10px;
}
.navigation {
display: flex;
align-items: center;
}
.navigation li {
display: inline;
padding: 0 10px;
}
<header>
Logo
<ul class="navigation">
<li>Start</li>
<li>Über</li>
<li>Weitere</li>
<li>Kontakt</li>
</ul>
</header>
If I understood right, here is the solution.
body {
font-family: sans-serif;
box-sizing: border-box;
}
header {
display: flex;
flex-direction: row;
}
.logo{
margin: 0 30px 0 0;
}
.navigation {
margin: 0;
padding: 0;
list-style: none;
display: flex;
flex-direction: row;
}
.navigation li {
margin: 0 10px 0 0;
padding: 0 10px 0 0;
}
<header>
<div class="logo">Logo</div>
<ul class="navigation">
<li>Start</li>
<li>Über</li>
<li>Weitere</li>
<li>Kontakt</li>
</ul>
</header>
Related
I'm trying to create a flex header with nav. However, my image doesn't seem to be responsive. As I'm minimizing the width the menu seems to act responsive but my logo image doesn't.
The image is a dummy one, when i set an image with these certain width and height (without adding any dimensions in property i have the same issue)
How can i solve this?
body {
margin: 0;
margin: 0;
width: 100%;
display: flex;
}
header {
width: 100%;
height: 91px;
background-color: #222222;
position: relative;
}
a {
text-decoration: none;
color: #fff;
font-size: 15px;
line-height: 17.22px;
}
ul {
list-style: none;
}
nav {
display: flex;
justify-content: space-between;
}
nav ul {
display: flex;
justify-content: center;
align-items: center;
margin-right: 280px;
}
li {
margin-left: 35px;
}
nav img {
display: flex;
margin-left: 254px;
position: relative;
}
<body>
<header>
<nav>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
<ul>
<li style="margin-left:0;">Hompage</li>
<li>About us</li>
<li>Our Services</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</header>
</body>
Preserve aspect ratio:
img {
height: 91px;
width: auto;
}
please check the code you need to add height: 91px; object-fit: contain; in logo image and set max-width for responsive you need to add media query I have mention in code so you can check it.
body {
margin: 0;
margin: 0;
width: 100%;
display: flex;
flex-direction:column;
}
header {
width: 100%;
padding: 10px 0;
background-color: #d2d2d2;
position: relative;
}
a {
text-decoration: none;
color: #000;
font-size: 15px;
}
ul {
list-style: none;
padding:0;
margin:0;
}
nav {
display: flex;
justify-content: space-between;
padding:0 5%;
}
nav ul {
display: flex;
justify-content: center;
align-items: center;
}
li {
margin-right: 35px;
}
li:last-child {
margin-right:0px;
}
nav img {
display: flex;
position: relative;
height: 91px;
object-fit: contain;
width: 100%;
max-width: 100px;
}
#media screen and (max-width:575px){
nav{flex-direction:column;}
nav ul {
display: flex;
justify-content: left;
align-items: center;
margin-top: 20px;
flex-wrap: wrap;
}
}
<body>
<header>
<nav>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Logo_brand_Adidas.png/800px-Logo_brand_Adidas.png" alt="Digital Wise Logo" width="404" height="91">
<ul>
<li style="margin-left:0;">Hompage</li>
<li>About us</li>
<li>Our Services</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
</header>
</body>
I'm trying to arrange two empty divs as background elements behind a menu. All three elements are direct children of a flex container, but none of them will respect z-index, and I can't identify the cause. They will respect z-index when I set a position attribute, but then they lose the ability to flex.
html {
margin: 0;
padding: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
font-size: 100%;
}
#menuWrapper {
display: flex;
flex-flow: column wrap;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#menuBox {
z-index: 10;
width: 100%;
display: flex;
}
#menuBG {
z-index: 1;
margin: 0;
width: 100%;
min-height: 140px;
background-color: #000;
flex: 1;
}
#menuBar {
z-index: 2;
background-color: #d50000;
width: 100%;
min-height: 60px;
margin: 140px 0 0 0;
flex: 1;
}
header {
background-color: #FFF;
border-radius: 4px;
padding: 10px;
margin: 25px 25px 15px 3%;
width: auto;
height: auto;
flex: 0;
}
#siteHeading {
color:#d50000;
text-align: end;
font-style: italic;
display: flex;
flex-direction: column-reverse;
min-width: 400px;
margin: auto 4% 0 auto;
flex: 2 0;
}
nav {
display: flex;
flex-direction: column;
align-content: end;
flex: 1;
font-size: 2rem;
}
nav ul {
list-style: none;
margin: 0 4% 10px;
display: flex;
flex: 1;
flex-wrap: wrap;
justify-content: flex-end;
align-items: flex-end;
}
nav ul li {
margin-left: 5%;
}
nav a {
color: #000F;
text-decoration: none;
}
<body>
<div id="menuWrapper">
<div id="menuBox">
<header>
<img src="./imgs/A++ManufacturingLogo.png" alt="A++ Manufacturing Logo">
</header>
<nav>
<h1 id="siteHeading">A++ Manufacturing</h1>
<ul id="menu">
<li>Home</li>
<li>Products</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div id="menuBG"></div>
<div id="menuBar"></div>
</div>
</body>
A bit unsure what your end goal is. I assume it is to have the menuBox section act as a sort of "navbar" that covers any elements below it and sticks to the top.
Regardless, after throwing your code into a Codepen, and after adding margin-top: -200px; to the menuBG element, z-index seems to be working just fine. It might have been that you did not have background-color set on the menuBox, which made it seem like the menuBG was covering it.
See the Codepen link for an example showing that your z-index's are working just fine, even without setting position.
https://codepen.io/Bluhurr/pen/zYpJVQa
The z-index should be define as per example below. Also position attribute could be fixed, relative or absolute. But the key part is to define it.
.nav{
position: fixed;
display: flex;
flex-direction: row;
align-items: center;
width: 100%;
height: 96px;
background-color: var(--dark-bg);
z-index: 3; /* makes sure that navbar is on top of other elements */
}
You mean like this?
html {
margin: 0;
padding: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
font-size: 100%;
}
#menuWrapper {
display: flex;
flex-flow: column wrap;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#menuBox {
z-index: 10;
width: 100%;
display: flex;
}
#menuBG {
z-index: 1;
margin: 0;
width: 100%;
min-height: 140px;
background-color: #000;
flex: 1;
}
#menuBar {
z-index: 2;
background-color: #d50000;
width: 100%;
min-height: 60px;
margin: 140px 0 0 0;
flex: 1;
}
header {
background-color: #FFF;
border-radius: 4px;
padding: 10px;
margin: 25px 25px 15px 3%;
width: auto;
height: auto;
flex: 0;
}
#siteHeading {
color:#d50000;
text-align: end;
font-style: italic;
display: flex;
flex-direction: column-reverse;
min-width: 400px;
margin: auto 4% 0 auto;
flex: 2 0;
margin-top:-60px;
}
nav {
display: flex;
flex-direction: column;
align-content: end;
flex: 1;
font-size: 2rem;
}
nav ul {
list-style: none;
margin: 0 4% 10px;
display: flex;
flex: 1;
flex-wrap: wrap;
justify-content: flex-end;
align-items: flex-end;
}
nav ul li {
margin-left: 5%;
}
nav a {
color: #000F;
text-decoration: none;
}
<body>
<div id="menuWrapper ">
<div id="menuBox ">
<header id="menuBG">
<img src="./imgs/A++ManufacturingLogo.png" alt="A++ Manufacturing Logo">
</header>
<nav id="menuBar">
<h1 id="siteHeading">A++ Manufacturing</h1>
<ul id="menu ">
<li>Home</li>
<li>Products</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</body>
I'm having some problems creating a header.
Here, my ul is not using the full height of the nav, but the nav IS using the full height of the header.
I want to fix this in order to center vertically the text.
Thank you.
(edit) When I use height: 100%; on the ul, this happens.
This is my HTML:
<header>
<div class="logo">
<img src="img/logo.png"/>
</div>
<nav>
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>WORKS</li>
<li>CONTACT</li>
</ul>
</nav>
</header>
This is my SASS:
$BLACK:#000;
$WHITE:#fff;
* {
box-sizing: border-box;
}
header {
width: 100%;
height: 75px;
background-color: $BLACK;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
.logo {
width: 50%;
display: flex;
align-items: center;
padding-left: 50px;
}
nav {
width: 50%;
padding-right: 50px;
ul {
list-style-type: none;
display: flex;
flex-flow: row wrap;
justify-content: right;
li {
display: inline-block;
margin-left:50px;
a {
text-decoration: none;
color: $WHITE;
}
}
}
}
}
Here is a solution for this. Just add line-height: 75px; to the li elements and set the ul element's margin to zero by adding margin: 0px;.
* {
box-sizing: border-box;
}
header {
width: 100%;
height: 75px;
background-color: #000;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
header .logo {
width: 50%;
display: flex;
align-items: center;
padding-left: 50px;
}
header nav {
width: 50%;
padding-right: 50px;
}
header nav ul {
list-style-type: none;
display: flex;
flex-flow: row wrap;
justify-content: right;
margin: 0px;
}
header nav ul li {
display: inline-block;
margin-left: 50px;
line-height: 75px;
}
header nav ul li a {
text-decoration: none;
color: #fff;
}
<header>
<div class="logo">
<img src="img/logo.png"/>
</div>
<nav>
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>WORKS</li>
<li>CONTACT</li>
</ul>
</nav>
</header>
However I converted your SASS code into CSS to run it on the stack overflow code snippet runner. You can change this to SASS again if you want.
Thanks and best regards!
Its probably because you did not reset the margin for the ul tag and also apply a 100% percent height to it also.
$BLACK: #000;
$WHITE: #fff;
* {
box-sizing: border-box;
// margin: 0;
// padding: 0;
}
header {
width: 100%;
height: 75px;
background-color: $BLACK;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
.logo {
width: 50%;
display: flex;
align-items: center;
padding-left: 50px;
}
nav {
width: 50%;
padding-right: 50px;
background: red;
ul {
list-style-type: none;
display: flex;
flex-flow: row wrap;
justify-content: right;
background: orange;
height: 100%;
li {
display: inline-block;
margin-left: 50px;
a {
text-decoration: none;
color: $WHITE;
}
}
}
}
}
<header>
<div class="logo">
<img src="https://via.placeholder.com/20x20.png/09f/fff" />
</div>
<nav>
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>WORKS</li>
<li>CONTACT</li>
</ul>
</nav>
</header>
Please update your css with following code:
$BLACK:#000;
$WHITE:#fff;
* {
box-sizing: border-box;
}
header {
width: 100%;
height: 75px;
background-color: $BLACK;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
.logo {
width: 50%;
display: flex;
align-items: center;
padding-left: 50px;
}
nav {
width: 50%;
padding-right: 50px;
height: 100%;
display: flex;
align-items: center;
ul {
list-style-type: none;
display: flex;
flex-flow: row wrap;
justify-content: right;
flex: 1 0 auto;
align-self: stretch;
align-items: center;
li {
display: inline-block;
margin-left:50px;
a {
text-decoration: none;
color: $WHITE;
}
}
}
}
}
I'm trying to create a responsive navbar with three items in the same container in the middle as shown below.
For some reason the ul items are not being space evenly and it is showing me this:
I used these lines of code:
nav {
font-size: 1.5em;
display: flex;
justify-content: space-between;
}
ul {
flex: 1;
max-width: 50%;
display: flex;
justify-content: space-evenly;
}
ul,
li {
display: inline;
margin: 0;
padding: 0;
}
<nav>
Home
<ul>
<li>
Learn More
</li>
<li>
About
</li>
<li>
Contact
</li>
</ul>
Sign Up
</nav>
I appreciate any help and apologize if this post is unclear; I'm still new to this website.
What seemed to fix the issue was changing the "ul {...}" item in css to "nav ul{...}". Hopefully this can help out someone else in the future as well.
space-evenly or space-between will work!
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
display: block;
width: 90%;
margin: 5% auto;
}
nav {
display: flex;
justify-content: space-evenly;
}
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
}
li+li {
margin-left: 1.5rem;
float: left;
display: inline-block;
}
<header>
<nav>
Home
<ul>
<li>Learn More</li>
<li>About</li>
<li>Contact</li>
</ul>
Sign Up
</nav>
</header>
I'm a very new programmer working on a product landing project for FCC and am currently stuck trying to align the nav links under a logo image. Some bits of the css are messy or blank because I've been experimenting.
I've tried different margins, flex-directions, and padding.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrapper {
position: relative;
}
li {
list-style: none;
}
a {
color: #000;
text-decoration: none;
}
#header-img {
display: flex;
max-width: 75rem;
width: 45rem;
justify-content: center;
align-items: center;
text-align: center;
}
header {
position: fixed;
top: 0;
min-height: 7.5rem;
padding: 0rem 2rem;
display: flex;
justify-content: space-around;
align-items: center;
background-color: #A9A9A9;
}
nav {
width: 100%;
margin: ;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
padding: 0 5rem;
}
nav>ul {
width: 35vw;
display: flex;
flex-direction: row;
justify-content: space-around;
}
<div class="wrapper">
<header id="header">
<div class="logo">
<img id="header-img" src="https://i.imgur.com/G5nVsYG.png" alt="ar-15 logo" />
</div>
<nav id="nav-bar">
<ul>
<li><a class="nav-link" href="#points">What seperates us</a></li>
<li><a class="nav-link" href="#put-together">How to build</a></li>
<li><a class="nav-link" href="#product-price">Current Product Deals</a></li>
</ul>
</nav>
</header>
I expected the nav links to be under the image.
Add to header tag 'flex-wrap: wrap;'
I added what I wrote in the title and it lowered the NAV.
By the way, in CSS you should use Class.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrapper {
position: relative;
}
li {
list-style: none;
}
a {
color: #000;
text-decoration: none;
}
#header-img {
display: flex;
max-width: 75rem;
width: 45rem;
justify-content: center;
align-items: center;
text-align: center;
}
header {
position: fixed;
top: 0;
min-height: 7.5rem;
padding: 0rem 2rem;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
background-color: #A9A9A9;
}
nav {
width: 100%;
margin: ;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
padding: 0 5rem;
}
nav > ul {
/* width: 35vw; */
display: flex;
flex-direction: row;
justify-content: space-around;
}
nav ul li {
padding: 10px 10px;
}
<div class="wrapper">
<header id="header">
<div class="logo">
<img id="header-img" src="https://i.imgur.com/G5nVsYG.png" alt="ar-15 logo" />
</div>
<nav id="nav-bar">
<ul>
<li><a class="nav-link" href="#points">What seperates us</a></li>
<li><a class="nav-link" href="#put-together">How to build</a></li>
<li><a class="nav-link" href="#product-price">Current Product Deals</a></li>
</ul>
</nav>
</header>