Issue with centre alignment of text in flexbox and headings - html

Currently the text headings which are inside a flexbox (the three divs) are not aligning with the main headings on the rest of the page.
See Image Here
The issue appears to only take place with the character length of the text headings inside the flexbox of three divs are not the same.
See Image of Alignment when character length is the same
I've unsuccessfully tried css alignments, but they do not appear to have an effect. My desired outcome for the three divs is something like this:
See successful reference alignment example
The code is here:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
max-width: 100vw;
list-style: none;
scroll-behavior: smooth;
}
body {
height: 100%;
margin: 0;
background-color: white;
font-family: Poppins;
min-height: 100vh;
}
a {
color: black;
}
/* ----------------------------------------------------------Landing Page -------------------------------------*/
.full-height-grow {
height: 100%;
display: flex;
flex-direction: column;
}
section {
display: flex;
height: 100vh;
width: auto;
max-width: 80vw;
min-width: 75vw;
justify-content: center;
align-items: center;
margin: 0 auto;
}
.about-container {
padding-top: 100px;
height: 100vh;
width: 90vw;
max-width: 90vw;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.about-img {
border-radius: 50%;
height: calc(80px + 40%);
width: auto;
}
.about-h1 {
font-family: 'Poppins', sans-serif;
color: rgb(255, 42, 95);
margin-top: 30px;
margin-right: -30px;
margin-left: -30px;
font-size:calc(12px + 0.8vw) ;
}
.about-h2 {
font-family: 'Poppins', sans-serif;
color: rgb(17, 17, 17);
margin-right: -30px;
margin-left: -30px;
font-size:calc(15px + 2vw) ;
font-weight: 500;
opacity: 0.9;
}
.about-desc {
font-family: Lora;
font-size:calc(10px + 1.2vw);
line-height: 1.8;
color: #888888;
text-align: center;
margin-left: 25vw;
margin-right: 25vw;
overflow:hidden;
z-index: 2;
width: auto;
}
.about-tasks-container {
align-self: center;
background-color: blanchedalmond;
max-width: 80vw;
width: 80vw;
display: flex;
justify-content: space-evenly;
text-align: center;
flex-direction: row;
flex-grow: 1;
}
.about-task-heading {
font-size: 80px;
}
.about-tasks-resources {
}
.about-tasks-learning {
}
<section class="about-section">
<div class="about-container" id="about">
<h2 class="about-h1"> ABOUT</h2>
<h3 class="about-h2">More About Me</h3>
<div class="about-tasks-container">
<div class="about-tasks-tutorials">
<h1 class="about-task-heading">Example</h1>
</div>
<div class="about-tasks-resources" >
<h1 class="about-task-heading">Exampler</h1>
</div>
<div class="about-tasks-learning">
<h1 class="about-task-heading">Examplers</h1>
</div>
</div>
</div>
</div>
</section>
(JSFiddle : https://jsfiddle.net/2cL5h4m6/9/)

Try this code
Idk if this is what you wanted but you can try it and you can see if it was the thing you looked for
* {
margin: 0;
padding: 0;
box-sizing: border-box;
max-width: 100vw;
list-style: none;
scroll-behavior: smooth;
}
body {
height: 100%;
margin: 0;
background-color: white;
font-family: Poppins;
min-height: 100vh;
}
a {
color: black;
}
/* ----------------------------------------------------------Landing Page -------------------------------------*/
.full-height-grow {
height: 100%;
display: flex;
flex-direction: column;
}
section {
display: flex;
height: 100vh;
width: auto;
max-width: 80vw;
min-width: 75vw;
justify-content: center;
align-items: center;
margin: 0 auto;
}
.about-container {
padding-top: 100px;
height: 100vh;
width: 90vw;
max-width: 90vw;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.about-img {
border-radius: 50%;
height: calc(80px + 40%);
width: auto;
}
.about-h1 {
font-family: 'Poppins', sans-serif;
color: rgb(255, 42, 95);
margin-top: 30px;
margin-right: -30px;
margin-left: -30px;
font-size:calc(12px + 0.8vw) ;
}
.about-h2 {
font-family: 'Poppins', sans-serif;
color: rgb(17, 17, 17);
margin-right: -30px;
margin-left: -30px;
font-size:calc(15px + 2vw) ;
font-weight: 500;
opacity: 0.9;
}
.about-desc {
font-family: Lora;
font-size:calc(10px + 1.2vw);
line-height: 1.8;
color: #888888;
text-align: center;
margin-left: 25vw;
margin-right: 25vw;
overflow:hidden;
z-index: 2;
width: auto;
}
.about-tasks-container {
align-self: center;
background-color: blanchedalmond;
max-width: 100vw;
width: 100vw;
display: flex;
justify-content: space-evenly;
text-align: center;
flex-direction: row;
flex-grow: 0;
}
.about-task-heading {
font-size: 30px;
}
.about-tasks-resources {
}
.about-tasks-learning {
}```

Related

How use media-quires in CSS?

I'm making web-site , and i need make adaptive site. So i began use media-quires and got a trouble. When screen resolution has been changing in example since 2560px to 1920px , some styles remain in site, however they hasn't written in code CSS, why ?
#media only screen and (max-width: 2560px ) {
body {
background-color: #344B56;
color: white;
font-family: Montserrat;
margin: 0px;
padding-top: 20px;
}
.container {
margin: 0 auto;
}
.info {
display: flex;
justify-content: space-around;
align-items: flex-start;
padding-bottom: 5px;
}
.company {
text-decoration: none;
color: white;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
font-size: 30px;
text-align: center;
}
.company p {
margin: 0px;
}
.hours, .adress, .callback {
display: flex;
align-items: flex-start;
}
.logo {
width: 50px;
padding-top: 12px;
padding-right: 10px;
}
.navbar {
display: flex;
justify-content: space-evenly;
padding: 20px;
border-top: 1px white solid;
border-radius: 50px;
}
.completed {
font-size: 20px;
font-family: Montserrat;
border-bottom: 2px skyblue solid;
border-radius: 5px;
margin: 0px;
padding: 0px;
}
.navbar a {
letter-spacing: -2px;
color: white;
font-size: 20px;
font-family: Montserrat;
text-decoration: none;
}
.navbar a:hover {
color: skyblue;
}
.company_info {
display: flex;
justify-content: space-around;
align-items: center;
background-color: #323a42;
}
.company_text {
display: flex;
flex-direction: column;
width: 500px;
padding: 50px;
}
.infoCompany {
background-image: url("./images/companyBack.jpeg");
background-position: center center;
background-size: cover;
width: 100%;
height: 600px;
}
.infoCompany__Text {
display: flex;
flex-direction: column;
color: white;
width: 100%;
font-size: 26px;
}
.infoCompany__Text_Company {
display: flex;
margin-top: 100px;
margin-left: 200px;
}
.Service {
margin-top: 50px;
margin-left: 200px;
margin-right: 200px;
color: white;
font-size: 24px;
}
.Service__Products {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
}
.Service__Products_Product {
display: flex;
flex-direction: column;
margin-top: 50px;
}
.Service__Products_Product:not(first-child) {
margin-left: 150px;
}
.Product__img {
width: 500px;
height: 402px;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
}
.Product__DownPartCard {
display: flex;
}
.Product__LeftDivCard {
width: 24px;
height: 98px;
background-color: #1A81AD;
}
.Product__NameCardDiv {
width: 476px;
height: 98px;
background: white;
}
.Product__DownPartCard_Text {
font-size: 18px;
display: flex;
color: black;
padding-left: 15px;
padding-top: 30px;
}
.Garant {
color: white;
margin-top: 100px;
margin-left: 200px;
margin-right: 200px;
color: white;
font-size: 24px;
}
.Garant__Garants {
margin-top: 70px;
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.Garant__Card {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.Gatant__Card_Img {
width: 150px;
height: 150px;
}
.Gatant__Card_Text {
font-size: 16px;
}
footer {
margin-top: 70px;
position: absolute;
width: 100%;
border-top: 1px white solid;
}
.invisible {
opacity: 0;
}
}
#media only screen and (max-width: 1920px ) {
body {
background-color: #344B56;
color: white;
font-family: Montserrat;
margin: 0px;
padding-top: 20px;
}
.container {
margin: 0 auto;
}
.info {
display: flex;
justify-content: space-around;
align-items: flex-start;
padding-bottom: 5px;
}
.company {
text-decoration: none;
color: white;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
font-size: 30px;
text-align: center;
}
.company p {
margin: 0px;
}
.hours, .adress, .callback {
display: flex;
align-items: flex-start;
}
.logo {
width: 50px;
padding-top: 12px;
padding-right: 10px;
}
.navbar {
display: flex;
justify-content: space-evenly;
padding: 20px;
border-top: 1px white solid;
border-radius: 50px;
}
.completed {
font-size: 20px;
font-family: Montserrat;
border-bottom: 2px skyblue solid;
border-radius: 5px;
margin: 0px;
padding: 0px;
}
.navbar a {
letter-spacing: -2px;
color: white;
font-size: 20px;
font-family: Montserrat;
text-decoration: none;
}
.navbar a:hover {
color: skyblue;
}
.company_info {
display: flex;
justify-content: space-around;
align-items: center;
background-color: #323a42;
}
.company_text {
display: flex;
flex-direction: column;
width: 500px;
padding: 50px;
}
.infoCompany {
background-image: url("./images/companyBack.jpeg");
background-position: center center;
background-size: cover;
width: 100%;
height: 600px;
}
.infoCompany__Text {
display: flex;
flex-direction: column;
color: white;
width: 100%;
font-size: 26px;
}
.infoCompany__Text_Company {
display: flex;
margin-top: 100px;
margin-left: 200px;
}
.Service {
margin-top: 50px;
margin-left: 200px;
margin-right: 200px;
color: white;
font-size: 24px;
}
.Service__Products {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
}
.Service__Products_Product {
display: flex;
flex-direction: column;
margin-top: 50px;
}
.Product__img {
width: 400px;
height: 302px;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
}
.Product__DownPartCard {
display: flex;
}
.Product__LeftDivCard {
width: 12px;
height: 98px;
background-color: #1A81AD;
}
.Product__NameCardDiv {
width: 388px;
height: 98px;
background: white;
}
.Product__DownPartCard_Text {
font-size: 15px;
display: flex;
color: black;
padding-left: 15px;
padding-top: 30px;
}
.Garant {
color: white;
margin-top: 100px;
margin-left: 200px;
margin-right: 200px;
color: white;
font-size: 24px;
}
.Garant__Garants {
margin-top: 70px;
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.Garant__Card {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.Gatant__Card_Img {
width: 150px;
height: 150px;
}
.Gatant__Card_Text {
font-size: 16px;
}
footer {
margin-top: 70px;
position: absolute;
width: 100%;
border-top: 1px white solid;
}
.invisible {
opacity: 0;
}
}
#media only screen and (max-width: 1500px) {
body {
background-color: #344B56;
color: white;
font-family: Montserrat;
margin: 0px;
padding-top: 20px;
}
.container {
margin: 0 auto;
}
.info {
display: flex;
justify-content: space-around;
align-items: flex-start;
padding-bottom: 5px;
}
.company {
text-decoration: none;
color: white;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
font-size: 30px;
text-align: center;
}
.company p {
margin: 0px;
}
.hours, .adress, .callback {
display: flex;
align-items: flex-start;
}
.logo {
width: 50px;
padding-top: 12px;
padding-right: 10px;
}
.navbar {
display: flex;
justify-content: space-evenly;
padding: 20px;
border-top: 1px white solid;
border-radius: 50px;
}
.completed {
font-size: 20px;
font-family: Montserrat;
border-bottom: 2px skyblue solid;
border-radius: 5px;
margin: 0px;
padding: 0px;
}
.navbar a {
letter-spacing: -2px;
color: white;
font-size: 20px;
font-family: Montserrat;
text-decoration: none;
}
.navbar a:hover {
color: skyblue;
}
.company_info {
display: flex;
justify-content: space-around;
align-items: center;
background-color: #323a42;
}
.company_text {
display: flex;
flex-direction: column;
width: 500px;
padding: 50px;
}
.infoCompany {
background-image: url("./images/companyBack.jpeg");
background-position: center center;
background-size: cover;
width: 100%;
height: 600px;
}
.infoCompany__Text {
display: flex;
flex-direction: column;
color: white;
width: 100%;
font-size: 26px;
}
.infoCompany__Text_Company {
display: flex;
margin-top: 100px;
margin-left: 200px;
}
.Service {
color: white;
font-size: 24px;
text-align: center;
}
.Service__Products {
display: flex;
flex-wrap: wrap;
}
.Service__Products_Product {
width: 100%;
display: flex;
flex-direction: column;
margin: 50px 0 0 0;
}
.Product__img {
width: 400px;
height: 302px;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
}
.Product__downPartCard {
display: flex;
}
.Product__leftDivCard {
width: 12px;
height: 98px;
background-color: #1A81AD;
}
.Product__NameCardDiv {
width: 388px;
height: 98px;
background: white;
}
.Product__DownPartCard_Text {
font-size: 15px;
display: flex;
color: black;
padding-left: 15px;
padding-top: 30px;
}
.Garant {
color: white;
margin-top: 100px;
margin-left: 200px;
margin-right: 200px;
color: white;
font-size: 24px;
}
.Garant__Garants {
margin-top: 70px;
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.Garant__Card {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.Gatant__Card_Img {
width: 150px;
height: 150px;
}
.Gatant__Card_Text {
font-size: 16px;
}
footer {
margin-top: 70px;
position: absolute;
width: 100%;
border-top: 1px white solid;
}
.invisible {
opacity: 0;
}
}
So "margin-left: 150px ;" from media 2560px somehow using in 1920px, why ?
.Service__products_Product:not(first-child) {
margin-left: 150px ;
}
/* Extra small devices (phones, 360px) to Large devices (laptops/desktops, 1920px) */
#media screen and (min-width: 360px) and (max-width: 1920px) { css here...}
/* Extra Large devices (laptops/desktops, 1921px and up) */
#media screen and (min-width: 1921px) {css here...}

Adding bottom padding or margin to an element gives unwanted width to entire page

/* GLOBAL STYLES */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
h1{
Font-Family: 'Ovo', Serif;
font-size: 90px;
}
h2,h3,h4,h5,h6,p{
Font-Family: 'Quattrocento Sans', Sans-Serif;
}
:root{
--bg1: #E8E0D2;
--bg2: #9B9FAE;
--green: #5F6D45;
--font: #F5F1F1;
}
body{
width: 1920px;
max-width: 1920px;
background-color: var(--bg1);
}
.separator{
width: 80%;
margin: auto;
padding: 150px 0;
}
.line{
border-top: 1px solid var(--bg2);
}
html{
max-width: 1920px;
}
/* HEADER */
header{
width: 1920px;
height: 100px;
position: relative;
}
.header-container{
margin: auto;
width: 1520px;
height: inherit;
display: flex;
border-bottom: 1px solid black;
}
.header-container nav{
width: 50%;
height: inherit;
}
.logo{
position: relative;
bottom: 32px;
}
.nav-right{
display: flex;
justify-content: flex-end;
}
.nav-right ul{
width: 75%;
display: flex;
align-items: flex-end;
justify-content: space-between;
}
#nav-link{
display: flex;
display: inline-block;
}
#nav-link a{
float: right;
text-decoration: none;
color: black;
}
.nav-right h2{
font-size: 19px;
}
/* MAIN */
main{
display: flex;
flex-direction: column;
height: 800px;
width: 1920px;
margin: auto;
}
/* HERO */
.hero{
width: inherit;
height: inherit;
/* background-color: teal; */
}
.hero-container{
height: inherit;
display: flex;
justify-content: center;
}
#hero-half{
width: 100%;
/* border: 1px solid red; */
}
.hero-left{
display: flex;
justify-content: end;
}
.hero-left .container{
width: 79%;
height: 80%;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.name-intro h2{
color: var(--green);
font-size: 18px;
}
.name-intro h2{
}
.info-box{
position: relative;
top: 100px;
width: 50%;
background-color: var(--green);
padding: 15px;
border-radius: 3px;
box-shadow:-20px -10px var(--bg2);
}
.slogan{
color: white;
font-size: 20px;
letter-spacing: 1.1px;
line-height: 1.3;
text-align: center;
}
.hero-right{
display: flex;
justify-content: flex-end;
align-items: flex-end;
}
.img-container{
display: flex;
justify-content: center;
align-items: center;
background-color: var(--green);
width: 650px;
height: 650px;
border-radius: 3px;
background-image: url('./bg texture3.jpg');
background-blend-mode: multiply;
}
.me-img{
position: relative;
right: 75px;
width: 400px;
height: 560px;
}
.me-img img{
width: inherit;
height: inherit;
}
I Use a separator to add space and a horizontal line between the different sections of my webpage so they aren't touching, but whenever I either add margin or padding to the bottom of it the entire width of the page grows a tiny bit and now there's the sidescroll option. The extra width also appears when I add bottom margin directly to the sections themselves. Any help would be appreciated!
I've tried adding max-width to the page, but it still expands.
In your body and header, try changing width: 1920px; to max-width: 100%;. Also, in "hero-left", you may want to change that to "max-width" as well. In most cases, you wouldn't want to use width: 100%;

Alignment of text in CSS

I am trying to make a list with perfect alignment.
I have entered three items in the list but my list of with grey back ground is not appearing as same alignment as in the below picture.
My box width is changing according to the size of the font. I am providing both image in perfect same alignment and my image with two list item with not same width of grey background.
Below is the my css code:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 22px;
}
body {
min-height: 100vh;
font-family: 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.App {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
max-width: 500px;
border: 1px solid mediumblue;
margin: auto;
}
header {
width: 100%;
padding: 0 0.25em;
background-color: mediumblue;
color: aliceblue;
display: flex;
justify-content: space-between;
align-items: center;
}
main {
width: 100%;
display: flex;
flex-direction: column;
flex-grow: 1;
justify-content: center;
align-items: center;
overflow-y: auto;
}
footer {
width: 100%;
padding: 0.25em;
background-color: mediumblue;
color: aliceblue;
display: grid;
place-content: center;
}
ul {
width: 100%;
list-style: none;
padding: 0 0.25rem 0.25rem;
}
ul li::before {
content: "\200B";
}
.item {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 0.5rem 0 0.5rem 0.5rem;
margin: 0.25rem 0;
background-color: #eee;
}
.item: first-child {
margin: 0;
}
.item input[type="checkbox"] {
text-align: center;
width: 2.5rem;
width: 48px;
min-width: 48px;
height: 2.5rem;
height: 48px;
min-height: 48px;
cursor: pointer;
margin-right: 0.5rem;
}
.item input[type="checkbox"]:focus + label {
text-decoration: underline;
}
.item > label {
font-size: 0.75rem;
flex-grow: 1;
}
.item svg {
width: 48px;
min-width: 48px;
height: 36px;
font-size: 1rem;
color: steelblue;
cursor: pointer;
}
.item svg:focus,
.item svg:hover {
color: red;
outline: none;
}
Please guide me where I am doing mistake and why my grey background boxes are not same width as the below image.

Flex-wrap only wraps one item in container

Situation: I have a div with flex and h1 and h3 children inside it.
Problem: The flex-wrap does not apply correctly to the h1 element.
What I tried: I have tried applying width, and max-width to the container but the h1 tag doesn't wrap when resized but the h3 does.
I've tried to apply height as well. I've applied the flex properties to other containers but no matter what the h1 won't move. The h1 doesn't wrap to the other line. It just stays put and gets engulfed by the overflow when the browser resizes.
Expected result: the h1 must wrap its letters when resizing the screen.
Snippet:
* {
box-sizing: border-box;
font-family: Francois One;
}
body {
margin: 0;
font-family: Francois One;
font-size: 1rem;
line-height: 1.5;
overflow-x: hidden;
}
.v-header {
height: 100vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.container {
padding-left: 1rem;
padding-right: 1rem;
margin: auto;
text-align: center;
}
.fullscreen-img-wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
overflow: hidden;
}
.fullscreen-img-wrap img {
min-width: 100%;
min-height: 100vh;
}
.header-overlay {
height: 100vh;
width: 100%;
position: absolute;
top: 0;
left: 0;
background: rgb(250, 134, 188);
opacity: 0.40;
z-index: 1
}
.header-content {
z-index: 2;
display: flex;
flex-wrap: wrap;
justify-content: center;
overflow: hidden;
}
.header-content h1 {
font-size: 50px;
color: rgb(255, 255, 255);
font-family: Alfa Slab One;
letter-spacing: 10px;
text-transform: uppercase;
-webkit-text-fill-color: transparent;
-webkit-text-stroke-width: 2px;
}
.header-content h3 {
color: rgb(247, 45, 146);
}
<header class="v-header container">
<div class="fullscreen-img-wrap">
<img src="giphy.gif" alt="audio waves">
</div>
<div class="header-overlay"></div>
<div class="header-content">
<h1 class="display-4">20Somethingandliving</h1>
<h3>Podcast</h3>
</div>
</header>
I think you want to break the word? because your h1 is missing the spaces, without telling the element to break the word it will overflow.
Solution:
word-break: break-word;// or break-all;
Working snippet:
* {
box-sizing: border-box;
font-family: Francois One;
}
body {
margin: 0;
font-family: Francois One;
font-size: 1rem;
line-height: 1.5;
overflow-x: hidden;
}
.v-header {
height: 100vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.container {
padding-left: 1rem;
padding-right: 1rem;
margin: auto;
text-align: center;
}
.fullscreen-img-wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
overflow: hidden;
}
.fullscreen-img-wrap img {
min-width: 100%;
min-height: 100vh;
}
.header-overlay {
height: 100vh;
width: 100%;
position: absolute;
top: 0;
left: 0;
background: rgb(250, 134, 188);
opacity: 0.40;
z-index: 1
}
.header-content {
z-index: 2;
display: flex;
flex-wrap: wrap;
justify-content: center;
overflow: hidden;
}
.header-content h1 {
word-break: break-word;
font-size: 50px;
color: rgb(255, 255, 255);
font-family: Alfa Slab One;
letter-spacing: 10px;
text-transform: uppercase;
-webkit-text-fill-color: transparent;
-webkit-text-stroke-width: 2px;
}
.header-content h3 {
color: rgb(247, 45, 146);
}
<header class="v-header container">
<div class="fullscreen-img-wrap">
<img src="giphy.gif" alt="audio waves">
</div>
<div class="header-overlay"></div>
<div class="header-content">
<h1 class="display-4">20Somethingandliving</h1>
<h3>Podcast</h3>
</div>
</header>

Why is this logo not centering vertically within its parent container?

The logo element in this page is not centering vertically within the <header> container. The problem is more pronounced on mobile than on desktop. The second element (#forum-link) is aligning correctly.
The flexbox align-items:center rule seems to work for one child div but not the other. Why is that the case and how do you fix it?
html {
max-width: 780px;
margin: 0 auto;
}
body {
background-image: url('https://img.freepik.com/free-vector/retro-styled-pattern-background_1048-6593.jpg');
background-size: 116px;
background-repeat: repeat-x;
}
header {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
height:116px;
}
#logo {
margin-left: 15px;
}
#forum-link {
max-width: 110px;
margin-right: 35px;
}
#forum-link a {
color: white;
text-decoration: none;
font-weight: bold;
font-size: x-large;
}
#media only screen and (orientation: portrait) {
html {
margin: 0;
height: 100%;
}
body {
margin: 0;
height: 100%;
display: flex;
flex-flow: column;
}
header {
display: block;
width: 100%;
position: relative;
height: auto;
margin-bottom: 50px;
}
#logo {
margin: initial;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link {
margin: initial;
max-width: initial;
background: #323232;
height: 27px;
position: absolute;
bottom: -50px;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link a {
font-weight: bold;
font-size: .9em;
}
#forum-link a:hover {
text-decoration: underline;
}
<body>
<header>
<div id="logo"><img src="http://placekitten.com/g/354/85" srcset="http://placekitten.com/g/354/85, http://placekitten.com/g/354/85 2x" width="354" height="85"></div>
<div id="forum-link">Join our Forums!</div>
</header>
</body>
EDIT: Clarified the question
Umm, I think this is what you're after: logo and link is vertically centred on the bg? Only updated for non-mobile solution.
Also, as I said in my comment, repeated here for comprehensiveness: your image isn't vertically centring because it's the height of its parents: the #logo and header.
The link has a smaller height than the header, so it's vertically centring.
If you're referring to the 5px or so of space, just throw a display: block on your #logo's image to remove that spacing. It will still be the height of its parents though.
My solution basically gives your body a height, flex it and your header aligns itself vertically centred.
html {
max-width: 780px;
margin: 0 auto;
}
body {
background-image: url('https://img.freepik.com/free-vector/retro-styled-pattern-background_1048-6593.jpg');
background-size: 116px;
background-repeat: repeat-x;
height: 116px;
margin: 0;
display: flex;
}
header {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
margin-bottom: 0;
width: 100%;
}
#logo {
margin-left: 15px;
}
#logo img {
display: block;
}
#forum-link {
max-width: 110px;
margin-right: 35px;
}
#forum-link a {
color: white;
text-decoration: none;
font-weight: bold;
font-size: x-large;
}
#media only screen and (orientation: portrait) {
html {
margin: 0;
height: 100%;
}
body {
margin: 0;
height: 100%;
display: flex;
flex-flow: column;
}
header {
display: block;
width: 100%;
position: relative;
height: auto;
margin-bottom: 50px;
}
#logo {
margin: initial;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link {
margin: initial;
max-width: initial;
background: #323232;
height: 27px;
position: absolute;
bottom: -50px;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link a {
font-weight: bold;
font-size: .9em;
}
#forum-link a:hover {
text-decoration: underline;
}
<body>
<header>
<div id="logo"><img src="http://placekitten.com/g/354/85" srcset="http://placekitten.com/g/354/85, http://placekitten.com/g/354/85 2x" width="354" height="85"></div>
<div id="forum-link">Join our Forums!</div>
</header>
</body>
Just add margin: 0 in body :
html {
max-width: 780px;
margin: 0 auto;
}
body {
background-image: url('https://img.freepik.com/free-vector/retro-styled-pattern-background_1048-6593.jpg');
background-size: 116px;
background-repeat: repeat-x;
margin: 0;
}
header {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
height:116px;
}
#logo {
margin-left: 15px;
}
#forum-link {
max-width: 110px;
margin-right: 35px;
}
#forum-link a {
color: white;
text-decoration: none;
font-weight: bold;
font-size: x-large;
}
#media only screen and (orientation: portrait) {
html {
margin: 0;
height: 100%;
}
body {
margin: 0;
height: 100%;
display: flex;
flex-flow: column;
}
header {
display: block;
width: 100%;
position: relative;
height: auto;
margin-bottom: 50px;
}
#logo {
margin: initial;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link {
margin: initial;
max-width: initial;
background: #323232;
height: 27px;
position: absolute;
bottom: -50px;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link a {
font-weight: bold;
font-size: .9em;
}
#forum-link a:hover {
text-decoration: underline;
}
<body>
<header>
<div id="logo"><img src="http://placekitten.com/g/354/85" srcset="http://placekitten.com/g/354/85, http://placekitten.com/g/354/85 2x" width="354" height="85"></div>
<div id="forum-link">Join our Forums!</div>
</header>
</body>
You need to specify the width of your parents for it to center vertically. And then add text-align: center;. Change the styles of your #logo and #forum-link as below.
#logo {
flex: 1;
width: 50%;
text-align: center;
}
#forum-link {
max-width: 110px;
flex: 1;
width: 50%;
text-align: center;
}
I removed your margins because the preview here is very small and you wont notice that the elements were centered vertically. Feel free to put it back in your source code. Check code below
html {
max-width: 780px;
margin: 0 auto;
}
body {
background-image: url('https://img.freepik.com/free-vector/retro-styled-pattern-background_1048-6593.jpg');
background-size: 116px;
background-repeat: repeat-x;
}
header {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
margin-bottom: 23px;
}
#logo {
flex: 1;
width: 50%;
text-align: center;
}
#forum-link {
max-width: 110px;
flex: 1;
width: 50%;
text-align: center;
}
#forum-link a {
color: white;
text-decoration: none;
font-weight: bold;
font-size: x-large;
}
#media only screen and (orientation: portrait) {
html {
margin: 0;
height: 100%;
}
body {
margin: 0;
height: 100%;
display: flex;
flex-flow: column;
}
header {
display: block;
width: 100%;
position: relative;
height: auto;
margin-bottom: 50px;
}
#logo {
margin: initial;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link {
margin: initial;
max-width: initial;
background: #323232;
height: 27px;
position: absolute;
bottom: -50px;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
#forum-link a {
font-weight: bold;
font-size: .9em;
}
#forum-link a:hover {
text-decoration: underline;
}
<body>
<header>
<div id="logo"><img src="http://placekitten.com/g/354/85" srcset="http://placekitten.com/g/354/85, http://placekitten.com/g/354/85 2x" width="354" height="85"></div>
<div id="forum-link">Join our Forums!</div>
</header>
</body>