align-items center does not work - html

I am trying to vertically center the h1 with the a's in the span but somehow the navigation buttons are a couple pixels higher than the h1. I have tried solving this but i couldn't find a way. So i'm hoping you maybe know what the problem could be.
h1 {
font-family: sans-serif;
font-size: 2em;
font-weight: normal;
}
h1 a {
text-decoration: none;
color: black;
font-size: 1em;
}
.nav {
display: flex;
justify-content: center;
}
.nav nav {
width: 90%;
height: 100px;
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="nav">
<nav>
<div>
<h1>workout</h1>
</div>
<span>
<a id='home' href="index.html">index</a>
<a id='work' href="pricing.html">pricing</a>
<a id='contact' href="schedule.html">schedule</a>
</span>
</nav>
</div>

Just remove .nav div styling for this. check updated snippet below..
h1{
font-family: sans-serif;
font-size:2em;
font-weight:normal;
}
h1 a{
text-decoration: none;
color:black;
font-size: 1em;
}
/*.nav{
display: flex;
justify-content: center;
}*/
.nav nav{
width: 90%;
height: 100px;
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="nav">
<nav>
<div>
<h1>workout</h1>
</div>
<span>
<a id='home' href="index.html">index</a>
<a id='work' href="pricing.html">pricing</a>
<a id='contact' href="schedule.html">schedule</a>
</span>
</nav>
</div>

Related

Why my menu is merging with the input field ? I want it to be responsive

I am new to HTML CSS, can anyone tell me what am I doing wrong?
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--pink: #ff6161;
--white: #fff;
--black: #292828;
--font: "Roboto", sans-serif;
}
header {
min-height: 100px;
max-width: 100%;
background-color: var(--pink);
display: flex;
justify-content: center;
align-items: center;
}
.menu {
max-width: 10rem;
display: flex;
justify-content: center;
align-items: center;
}
.menu-items {
list-style-type: none;
padding-right: 30px;
font-family: var(--font);
font-size: 20px;
}
.menu-items a {
text-decoration: none;
color: var(--black);
}
.search-bar {
width: 700px;
}
.inp {
width: 100%;
height: 2rem;
}
<header>
<div class="search-bar">
<input class="inp" type="text" />
</div>
<ul class="menu">
<i class="fa-solid fa-house"></i>
<li class="menu-items"> Home</li>
<i class="fa-solid fa-store"></i>
<li class="menu-items">Store</li>
<i class="fa-solid fa-headset"></i>
<li class="menu-items">Support</li>
</ul>
</header>
It's because you're using align items: center and justify-content: center in your header at the same time.
You're basically forcing items inside header to move to the center.
In your CSS, when you are modifying the header, you are putting all elements inside of it in the same position.
Something you could to fix this is, give the header a relative position, and then manipulate each element inside the header individually.
Change your display for menu to contents:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--pink: #ff6161;
--white: #fff;
--black: #292828;
--font: "Roboto", sans-serif;
}
header {
min-height: 100px;
max-width: 100%;
background-color: var(--pink);
display: flex;
justify-content: center;
align-items: center;
}
.menu {
max-width: 10rem;
display: contents;
justify-content: center;
align-items: center;
}
.menu-items {
list-style-type: none;
padding-right: 30px;
font-family: var(--font);
font-size: 20px;
}
.menu-items a {
text-decoration: none;
color: var(--black);
}
.search-bar {
width: 700px;
}
.inp {
width: 100%;
height: 2rem;
}
<header>
<div class="search-bar">
<input class="inp" type="text" />
</div>
<ul class="menu">
<i class="fa-solid fa-house"></i>
<li class="menu-items"> Home</li>
<i class="fa-solid fa-store"></i>
<li class="menu-items">Store</li>
<i class="fa-solid fa-headset"></i>
<li class="menu-items">Support</li>
</ul>
</header>
The sum of the text widths of the menu Home Store Support will be greater than max-width: 10rem;
.menu {
display: flex;
justify-content: center;
align-items: center;
}

Unorder list not available in my website's footer?

I'm creating a website and wanted to put the contact info in the footer. I created the footer using several nested divs: a footer div --> footer-container div --> footer-left div and footer-right div (using display: flex i put them side by side with each other). The footer-left div contains a ul (unordered list) of external links; the footer-right div contains social media icons. I've included the code below:
.footer {
height: 150px;
width: 100vw;
background-color: #7D594F;
}
.footer-container {
display: block;
justify-content: space-between;
align-items: center;
}
.footer-left {
border: 2px solid red;
}
.footer-left ul {
display: flex;
justify-content: space-between;
align-items: center;
list-style-type: none;
border: 2px solid blue;
}
.footer-left ul li {
color: #ffffff;
font-family: montserrat, sans-serif;
text-shadow: none;
text-align: center;
margin: 0px;
width: 150px;
border: 2px solid green;
}
.footer-right {
display: flex;
justify-content: center;
align-items: center;
}
/*to scale down the icons, the #facebook should always be 10px bigger than the #instagram*/
#facebook {
height: 40px;
width: 40px;
}
#instagram {
height: 30px;
width: 30px;
}
.footer p {
color: #ffffff;
font-family: montserrat, sans-serif;
font-size: 10px;
text-align: center;
}
<div class="footer">
<div class="footer-container">
<!--Using flex to push both containers on opposite sides of the footer-->
<div class="footer-left">
<ul>
<li>About</li>
<li>Contact</li>
<li>We Are Hiring</li>
<li>Our Financial Services</li>
<li>Our Legal Services</li>
<li>Kangen Water</li>
</ul>
</div>
<div class="footer-right">
<img id="facebook" src="/images/icons/noun_social media icon_2255034.png" alt="Link to Facebook">
<img id="instagram" src="/images/icons/noun_instagram_3350460.png" alt="Link to Instagram">
</div>
</div>
</div>
But the unordered list is not visible. I created bordered around each element to make it easier to visualize:
body {
margin: 0;
}
.footer {
height: 150px;
width: 100vw;
background-color: #7D594F;
}
.footer-container {
display: flex;
justify-content: space-between;
align-items: center;
}
.footer-left {
border: 2px solid red;
}
.footer-left ul {
display: flex;
/*flex-flow: column nowrap;*/
flex-flow: row wrap;
justify-content: space-around;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
border: 2px solid blue;
}
.footer-left ul li {
color: #ffffff;
font-family: montserrat, sans-serif;
text-shadow: none;
text-align: center;
margin: 0px;
padding: .5em 1em;
width: 150px;
border: 2px solid green;
}
.footer-right {
display: flex;
justify-content: around;
align-items: center;
}
/*to scale down the icons, the #facebook should always be 10px bigger than the #instagram*/
#facebook {
height: 40px;
width: 40px;
}
#instagram {
height: 30px;
width: 30px;
}
.footer p {
color: #ffffff;
font-family: montserrat, sans-serif;
font-size: 10px;
text-align: center;
}
<div class="footer">
<div class="footer-container">
<!--Using flex to push both containers on opposite sides of the footer-->
<div class="footer-left">
<ul>
<li>About</li>
<li>Contact</li>
<li>We Are Hiring</li>
<li>Our Financial Services</li>
<li>Our Legal Services</li>
<li>Kangen Water</li>
</ul>
</div>
<div class="footer-right">
<img id="facebook" src="/images/icons/noun_social media icon_2255034.png" alt="Link to Facebook">
<img id="instagram" src="/images/icons/noun_instagram_3350460.png" alt="Link to Instagram">
</div>
</div>
</div>

float not working on text and image elements

I am trying to make a navbar using HTML and CSS but my CSS float: right and float: left statements aren't working, everything is still on the right side.
.nav {
width: 100%;
text-align: center;
display: flex;
align-items: center;
padding: 15px;
overflow: hidden;
}
.nav-item {
color: black;
display: block;
list-style-type: none;
text-decoration: none;
font-size: 1.2em;
font-weight: bold;
padding: 0px 8 px;
text-transform: uppercase;
}
<div class="header">
<div class="nav">
<img src="img/logo.png" class="logo" width=50 height=50>
<li class="nav-item">Download</li>
<li class="nav-item">Contact</li>
</div>
</div>
As was already mentioned in a comment you need to wrap your list items in a <ul> tag. This is both the correct syntax and will allow you to have the entire list of links go to the right.
I also added justify-content: space-between to tell flex to align items left/right, and display: inline-block to the nav-item for them to display in a single line, rather than stacked as block level elements.
.nav {
width: 100%;
text-align: center;
display: flex;
align-items: center;
justify-content: space-between;
overflow: hidden;
}
.nav-item {
color: black;
display: inline-block;
list-style-type: none;
text-decoration: none;
font-size: 1.2em;
font-weight: bold;
padding: 0px 8px;
text-transform: uppercase;
margin-left: auto;
}
<div class="header">
<div class="nav">
<img src="img/logo.png" class="logo" width=50 height=50>
<ul>
<li class="nav-item">Download</li>
<li class="nav-item">Contact</li>
</ul>
</div>
</div>
You're almost good, please don't use float, instead you can use display: flex and use margin-left: auto to move things to the left.
.nav {
width: 100%;
text-align: center;
display: flex;
align-items: center;
overflow: hidden;
}
.nav-item {
color: black;
display: block;
list-style-type: none;
text-decoration: none;
font-size: 1.2em;
font-weight: bold;
padding: 0px 8px;
text-transform: uppercase;
margin-left: auto;
}
<div class="header">
<div class="nav">
<img src="img/logo.png" class="logo" width=50 height=50>
<li class="nav-item">Download</li>
<li class="nav-item">Contact</li>
</div>
</div>

Positioning with flexbox?

Hello guys im trying to recreate this:
This is what i have:
I did everything except i cant seem to get the nav potion to the right of the page.Any suggestions what i can do to make it work? What is the best way to do it and why?
index.html :
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="./resources/css/style.css">
</head>
<body>
<header>
<div class="logo">
<img src="./resources/images/img-myt-logo.jpg" alt="Our logo">
<span>My Times</span>
</div>
<nav>
<span>World</span>
<span>U.S</span>
<span>Tech</span>
<span>Science</span>
</nav>
</header>
</body>
</html>
style.css :
header {
display: flex;
font-family: Verdana;
font-size: 14px;
font-weight: bold;
border-bottom: 1px solid black;
}
.logo{
display: flex;
align-items: center;
margin-left: 20px;
}
nav span {
display: inline-block;
padding-right: 40px;
justify-content: flex-end;
}
.logo span {
color: MediumAquamarine;
padding-left: 10px;
}
add justify-content: space-between; to header
header {
display: flex;
font-family: Verdana;
justify-content: space-between;
font-size: 14px;
font-weight: bold;
border-bottom: 1px solid black;
}
.logo{
display: flex;
align-items: center;
margin-left: 20px;
}
nav span {
display: inline-block;
padding-right: 40px;
justify-content: flex-end;
}
.logo span {
color: MediumAquamarine;
padding-left: 10px;
}
<header>
<div class="logo">
<img src="./resources/images/img-myt-logo.jpg" alt="Our logo">
<span>My Times</span>
</div>
<nav>
<span>World</span>
<span>U.S</span>
<span>Tech</span>
<span>Science</span>
</nav>
</header>
If I understand what you're asking, you need to justify the content so that it opens up space between your logo div and the nav element. Easiest way to do this is add justify-content to your CSS for the header...
header {
display: flex;
font-family: Verdana;
font-size: 14px;
font-weight: bold;
border-bottom: 1px solid black;
justify-content:space-between;
}
.logo{
display: flex;
align-items: center;
margin-left: 20px;
}
nav span {
display: inline-block;
padding-right: 40px;
justify-content: flex-end;
}
.logo span {
color: MediumAquamarine;
padding-left: 10px;
}
The justify-content you have on nav span would justify the content within the nav, not justify the nav element itself within the header.

Aligning divs in a header

.header {
background-color: yellow;
font-family: 'Arial';
display: inline-block;
}
.leftheader{
float: left;
}
#Logo{
font-size: 40px;
font-weight: 700;
display: inline-block;
}
#LogoLTD{
font-size: 20px;
display: inline-block;
}
.rightheader{
display: flex;
float: right;
}
.rightheader a{
color: black;
font-size: 20px;
font-weight: 700;
text-decoration: none;
}
<section class="header">
<div class="leftheader">
<div id="Logo">COMPANY NAME</div>
<div id="LogoLTD">LIMITED</div>
</div>
<div class="rightheader">
HOME
WHO
CONTACT
</div>
</section>
I have been trying to make a header for my site but I can't get the aligning right.
I want to have my links on the right of the page inside the yellow box.
The yellow colour should be inside the header class.
Then the leftheader div and the rightheader div should be inside the header class. And they should be positioned on the left and right but I cannot get this to work whatever I do :(
My HTML is:
<section class="header">
<div class="leftheader">
<div id="Logo">COMPANY NAME</div>
<div id="LogoLTD">LIMITED</div>
</div>
<div class="rightheader">
HOME
WHO
CONTACT
</div>
</section>
My CSS is:
.header {
background-color: yellow;
font-family: 'Arial';
display: inline-block;
}
.leftheader{
float: left;
}
#Logo{
font-size: 40px;
font-weight: 700;
display: inline-block;
}
#LogoLTD{
font-size: 20px;
display: inline-block;
}
.rightheader{
display: flex;
float: right;
}
.rightheader a{
color: black;
font-size: 20px;
font-weight: 700;
text-decoration: none;
}
You can do that using flex. Check out the code below.
.header {
background-color: yellow;
font-family: 'Arial';
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.leftheader{
display: flex;
align-items: flex-end;
}
#Logo{
font-size: 40px;
font-weight: 700;
display: inline-block;
}
#LogoLTD{
font-size: 20px;
display: inline-block;
padding-bottom: 5px;
}
.rightheader{
display: flex;
}
.rightheader a{
color: black;
font-size: 20px;
font-weight: 700;
text-decoration: none;
}
<section class="header">
<div class="leftheader">
<div id="Logo">COMPANY NAME</div>
<div id="LogoLTD">LIMITED</div>
</div>
<div class="rightheader">
HOME
WHO
CONTACT
</div>
</section>
Just add width: 100% to your header, things will look more like you want them:
.header {
background-color: yellow;
font-family: 'Arial';
display: inline-block;
width: 100%;
}
This should do the work.
.header {
display: flex;
flex-wrap: wrap;
background: yellow;
padding: 8px;
}
.leftheader {
display: inline-block;
color: red;
width: 60%;
}
.rightheader {
display: inline-block;
width: 40%;
text-align: right;
}