I'm using the justify-content:space-between to horizontally distribute all elements equally across my header. This works fine until I add padding-right:20px to my nav links. It shifts my header h2 element to the right, making it uneven. How do I keep the padding but have my elements equally aligned? Help appreciated, thank you.
https://jsfiddle.net/2fr3L8zh/14/
HTML
<header>
<div id="header-wrapper">
<nav>
<a>Projects</a>
<a>About</a>
<a>Contact</a>
</nav>
<h2>EMMANUEL OJIJI</h2>
<p>SOCIAL MEDIA HERE</p>
</div>
</header>
<section id="intro">
<div id="intro-wrapper">
<h1>I'm Lorem Ipsum — a Birmingham -based Visual Designer with a passion and
a firm belief in considered and meaningful design.</h1>
</div>
</section>
CSS
html {
margin: 0;
padding: 0;
height: 100%;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
height: 100px;
background-color: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
display: flex;
justify-content: center;
align-items: center;
padding-left: 50px;
padding-right: 50px;
}
#header-wrapper {
width: 90%;
display: flex;
justify-content: space-between;
align-items: center;
}
nav a {
padding-right: 20px;
}
#intro {
height: 90vh;
display: flex;
justify-content: center;
align-items: center;
}
#intro-wrapper {
display: flex;
text-align: center;
width: 50%;
}
#intro-wrapper h1 {
font-weight: 700;
font-family: 'Raleway', sans-serif;
font-size: 2.2em;
line-height: 60px;
color: #333;
}
Avoid the padding for the last element of the navigation:
nav a:not(:last-child)
html {
margin: 0;
padding: 0;
height: 100%;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
height: 100px;
background-color: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
display: flex;
justify-content: center;
;
align-items: center;
padding-left: 50px;
padding-right: 50px;
}
#header-wrapper {
width: 90%;
display: flex;
justify-content: space-between;
align-items: center;
}
nav a:not(:last-child) {
padding-right: 20px;
}
#intro {
height: 90vh;
display: flex;
justify-content: center;
align-items: center;
}
#intro-wrapper {
display: flex;
text-align: center;
width: 50%;
}
#intro-wrapper h1 {
font-weight: 700;
font-family: 'Raleway', sans-serif;
font-size: 2.2em;
line-height: 60px;
color: #333;
}
<header>
<div id="header-wrapper">
<nav>
<a>Projects</a>
<a>About</a>
<a>Contact</a>
</nav>
<h2>EMMANUEL OJIJI</h2>
<p>SOCIAL MEDIA HERE</p>
</div>
</header>
<section id="intro">
<div id="intro-wrapper">
<h1>I'm Lorem Ipsum — a Birmingham -based Visual Designer with a passion and a firm belief in considered and meaningful design.</h1>
</div>
</section>
Related
So I want the divs in the 'header-content-lower' element to wrap down (if they all do not fit on the screen) in a row but its not even working, I tried changing box-sizing of the childs or setting max-width of the parent element but I still do not have a clue whats wrong, please help, im so done - this is my code:
#import "main.css";
.site-header {
display: flex;
align-items: center;
flex-direction: column;
background-color: var(--main-color);
font-family: 'Ubuntu', sans-serif;
height: 150px;
}
.header-content-upper {
display: flex;
align-items: center;
justify-content: space-between;
height: 100px;
width: 90%;
color: var(--main-font);
font-size: 1.1vw;
}
.header-content-upper .header-brand {
color: var(--main-font);
font-family: Glosa;
text-align: center;
font-size: 3.5rem;
}
.header-content-upper .header-nav {
text-align: end;
}
.header-content-upper li {
list-style: none;
display: inline;
padding: 10px;
}
.header-content-lower {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
width: 1000px;
height: 50px;
border-top: 1px solid var(--second-font);
font-size: 1vw;
}
.header-content-lower div {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
height: 50px;
color: var(--second-font);
}
.header-content-lower div:nth-child(2n-1) {
border: 1px solid var(--second-font);
border-width: 0px 1px 0 1px;
}
.header-brand,
.header-news,
.header-nav {
flex: 1;
}
<header class="site-header">
<div class="header-content-upper">
<nav class="header-news">Subscribe & get 15% OFF</nav>
<span class="header-brand">Giovanni</span>
<div class="header-nav">
<ul>
<li>Call + (448) 777 55 00</li>
<li>CART (0)</li>
</ul>
</div>
</div>
<div class="header-content-lower">
<div>HOME</div>
<div>MENU</div>
<div>ORDER</div>
<div>BLOG</div>
<div>CONTACT</div>
</div>
</header>
It won't wrap since you defined a fixed width for .header-content-lower. This will make the container stay 1000px wide, even if the screen is smaller.
Replace width: 1000px; with max-width: 1000px;, remove flex: 1; from the child divs of .header-content-lower, and set a fixed width for them (e.g. width: 200px; so that they have the same width as in your example).
You need to play around with align-items and justify-content on .header-content-lower to change the behavior when wrapped, e.g. with a media query which targets a window width < 1000px.
#import "main.css";
.site-header {
display: flex;
align-items: center;
flex-direction: column;
background-color: var(--main-color);
font-family: 'Ubuntu', sans-serif;
height: 150px;
}
.header-content-upper {
display: flex;
align-items: center;
justify-content: space-between;
height: 100px;
width: 90%;
color: var(--main-font);
font-size: 1.1vw;
}
.header-content-upper .header-brand {
color: var(--main-font);
font-family: Glosa;
text-align: center;
font-size: 3.5rem;
}
.header-content-upper .header-nav {
text-align: end;
}
.header-content-upper li {
list-style: none;
display: inline;
padding: 10px;
}
.header-content-lower {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
max-width: 1000px;
height: 50px;
border-top: 1px solid var(--second-font);
font-size: 1vw;
}
.header-content-lower div {
display: flex;
align-items: center;
justify-content: center;
/* flex: 1;*/
height: 50px;
width: 200px;
color: var(--second-font);
}
.header-content-lower div:nth-child(2n-1) {
border: 1px solid var(--second-font);
border-width: 0px 1px 0 1px;
}
.header-brand,
.header-news,
.header-nav {
flex: 1;
}
<header class="site-header">
<div class="header-content-upper">
<nav class="header-news">Subscribe & get 15% OFF</nav>
<span class="header-brand">Giovanni</span>
<div class="header-nav">
<ul>
<li>Call + (448) 777 55 00</li>
<li>CART (0)</li>
</ul>
</div>
</div>
<div class="header-content-lower">
<div>HOME</div>
<div>MENU</div>
<div>ORDER</div>
<div>BLOG</div>
<div>CONTACT</div>
</div>
</header>
I wan't to add a p like this.
I can add it, but when I use margin-top to put it down, it affects the elements above like this.
I don't know how to solve this.
Thank you.
HTML.
<main>
<section class="home">
<div class="presentation">
<p class="hello">HELLO THERE</p>
<p>I'm Lautaro Rojas</p>
<p>Web developer</p>
<p class="scroll">SCROLL DOWN</p>
</div>
<div class="presentation-buttons">
<button>LATEST PROJECTS</button>
<button>MORE ABOUT ME</button>
</div>
</section>
</main>
CSS:
main {
width: 100%;
height: 100%;
.home {
width: 100%;
height: 100%;
background-image: url("../img/bg.jpg");
background-size: cover;
display: flex;
align-items: center;
.presentation {
width: 70%;
height: 100%;
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
gap: 5px;
p {
width: 50%;
margin: 0;
text-align: left;
color: $WHITE;
font-family: Merriweather-Regular;
font-size: 70px;
letter-spacing: 2px;
}
p[class="hello"] {
font-size: 30px;
color: $PINK;
}
p[class="scroll"] {
margin-top:180px;
font-size: 10px;
}
}
}
}
position: absolute; is your friend...
<main>
<section class="home">
<div class="presentation">
<p class="hello">HELLO THERE</p>
<p>I'm Lautaro Rojas</p>
<p>Web developer</p>
<p class="scroll">SCROLL DOWN</p>
</div>
<div class="presentation-buttons">
<button>LATEST PROJECTS</button>
<button>MORE ABOUT ME</button>
</div>
</section>
</main>
main {
width: 100%;
height: 100%;
.home {
width: 100%;
height: 100%;
background-image: url("../img/bg.jpg");
background-size: cover;
display: flex;
align-items: center;
.presentation {
width: 70%;
height: 100%;
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
gap: 5px;
position: relative;
p {
width: 50%;
margin: 0;
text-align: left;
color: $WHITE;
font-family: Merriweather-Regular;
font-size: 70px;
letter-spacing: 2px;
}
p[class="hello"] {
font-size: 30px;
color: $PINK;
}
p[class="scroll"] {
margin-top:180px;
font-size: 10px;
position: absolute;
}
}
}
}
I'm trying to place 3 images on the same row using flexbox. I also want to change the size of the first image as it is too big. However, my CSS rules are not being applied properly. I have the images each inside their own div with a class of flex-item-3 to indicate that they are flex items inside my flex container. However, I can't seem to override the default CSS rules.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
font-family: 'Lato', 'sans-serif', 'arial';
color: #fff;
font-size: 15px;
font-weight: 300;
text-transform: uppercase;
text-rendering: optimizeLegibility;
}
.wrapper {
max-width: 100%;
margin: 0 auto;
}
section {
padding: 80px 0;
}
h2 {
margin: 0;
padding: 0;
}
.flex {
display: flex;
justify-content: space-between;
background-image: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("img/truck.jpg");
background-size: cover;
background-position: center;
}
.flex-item {
padding-top: 15px;
height: 100vh;
}
.item1 {
padding-top: 0;
padding-left: 30px;
}
.logo {
height: 90px;
}
.main-nav ul {
display: flex;
margin: 0;
padding: 0;
list-style: none;
}
.main-nav a {
color: white;
padding: 1rem;
text-decoration: none;
}
.main-nav a:hover {
color: orange;
}
.hero {
position: absolute;
top: 50%;
left: 25%;
transform: translate(-50%, -50%);
}
.hero a {
text-decoration: none;
color: white;
display: block;
margin: 10px;
padding: 10px;
border-radius: 10px;
}
.btn {
background-color: orange;
}
.flex2 {
display: flex;
justify-content: center;
align-items: center;
}
.flex-item-2 {
color: #312c2c;
width: 100%;
text-align: center;
}
.second-flex-item p {
margin-top: 20px;
margin-bottom: 40px;
font-size: 19px;
color: #312c2c;
}
.second-flex-item h2 {
font-weight: 900;
font-size: 25px;
}
.flex-3 {
display: flex;
justify-content: center;
max-width: 100%;
}
.flex-3-items {
display: flex;
width: 100%;
height: auto;
}
<body class="wrapper">
<header class="flex">
<div class="flex-item item1">
<img src="Resources/img/moBurgerzLogo.png" class="logo">
</div>
<nav class="flex-item main-nav">
<ul>
<li>Our Story</li>
<li>Locations</li>
<li>Menu</li>
<li>Order now</li>
</ul>
</nav>
<div class="hero">
<h2>Best Burgers <br> In DA City(D.C)</h2>
<a href="#" class="btn" btn-full>Order now!</a>
<a href="#" class="btn" btn-ghost>View Menu!</a>
</div>
</header>
<section class="flex-2">
<div class="flex-item-2 second-flex-item">
<h2>Established in 2017 in D.M.V</h2>
<p class="story"> moBurgerz was founded in 2017 by owner Mahamed Ibrahim.<br> Since then we have been serving the best hand crafted burgers in the D.M.V.<br>All our meat is halal and all of our ingridients are organic.</p>
<img src="Resources/img/white_truck.jpeg" class="truck-img">
</div>
</section>
<section class="flex-3">
<div class="flex-3-item meal-photos photo-1">
<img src="Resources/img/cheeseSteak.jpg">
</div>
<div class="flex-3-item meal-photos">
<img src="Resources/img/goodMoanin.jpeg">
</div>
<div class="flex-3-item meal-photos">
<img src="Resources/img/moGul.jpeg">
</div>
</section>
</body>
.flex-3-item img { max-width:100%; } should do the trick.
Also, look at this: Auto Resize Image in CSS FlexBox Layout and keeping Aspect Ratio?
Try this
.logo {
width: 100%;
height: auto;
}
So basically I am trying to create nice splash page and the designer wants the links diagonal, circular, and all the same size, the <p>'s are gonna be links, but how can I make them all diagonal and all the same size circle?
I have tried a lot of different flexbox combinations I haven't tried CSS grid yet, that is going to be what I try next.
/*variable declarations*/
:root {
--teal: #37C8AB;
--white: #ffffff;
--black: #000000;
--lilac: #B380FF;
--purple: #7137C8;
--aqua: #008066;
}
/*page body*/
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.page-container {
background: var(--lilac);
margin-top: 10px;
padding-bottom: 5em;
padding-left: 2em;
padding-top: 5.8em;
}
/*Text Conatiner*/
.tcontainer-frame {
background: var(--purple);
border: var(--black) 2px solid;
display: flex;
justify-content: center;
align-items: center;
padding: 1em;
}
.tcontainer {
background: var(--black);
font-size: 24px;
padding: 12em 1em;
text-align: center;
}
.teal-font {
color: var(--teal);
}
/*Link container*/
.link-container {
display: flex;
flex-flow: column wrap;
padding: 4em;
text-align: center;
}
#newSolCircle {
align-items: center;
align-self: flex-start;
background: var(--teal);
border-radius: 100%;
display: flex;
flex: 1 1 0;
justify-content: center;
margin: 2em;
padding: 1em;
}
#patronCircle {
align-items: center;
align-self: center;
background: var(--aqua);
border-radius: 100%;
display: flex;
flex: 1 1 0;
margin: 2em;
padding: 1em;
}
#alchemistCircle {
align-items: center;
align-self: flex-end;
background: var(--purple);
border-radius: 100%;
display: flex;
flex: 1 1 0;
margin: 2em;
padding: 1em;
}
<body class="bg-dark">
<div class="container-fluid page-container">
<div class="row">
<div class="col-6 tcontainer-frame">
<div class="tcontainer"><span class="teal-font">Hello. You have landed on the Image Alchemists' web portal. We
welcome
you. Please make your
selection to the right.</span>
</div>
</div>
<div class="col-6 link-container">
<div id="newSolCircle">
<p>New Solicitor</p>
</div>
<div id="patronCircle">
<p>Patron</p>
</div>
<div id="alchemistCircle">
<p>Alchemist</p>
</div>
</div>
</div>
</div>
</body>
I am just hoping to get those 3 circles to all line up correctly and have them all be the same width and height. Thanks in advance for anyone's help.
Including width and height was necessary to make them of the same size and in circle shape.
Then i removed flex: 1 1 0; as the align-items property alone was solving the problem along with the width and height.
:root {
--teal: #37C8AB;
--white: #ffffff;
--black: #000000;
--lilac: #B380FF;
--purple: #7137C8;
--aqua: #008066;
}
/*page body*/
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.page-container {
background: var(--lilac);
margin-top: 10px;
padding-bottom: 5em;
padding-left: 2em;
padding-top: 5.8em;
}
/*Text Conatiner*/
.tcontainer-frame {
background: var(--purple);
border: var(--black) 2px solid;
display: flex;
justify-content: center;
align-items: center;
padding: 1em;
}
.tcontainer {
background: var(--black);
font-size: 24px;
padding: 12em 1em;
text-align: center;
}
.teal-font {
color: var(--teal);
}
/*Link container*/
.link-container {
display: flex;
flex-flow: column wrap;
padding: 4em;
text-align: center;
}
.circle {
border-radius: 100%;
display: flex;
height: 50px;
width: 50px;
margin: 2em;
padding: 1em;
justify-content: center;
}
#newSolCircle {
align-items: center;
align-self: flex-start;
background: var(--teal);
}
#patronCircle {
align-items: center;
align-self: center;
background: var(--aqua);
}
#alchemistCircle {
align-items: center;
align-self: flex-end;
background: var(--purple);
}
<body class="bg-dark">
<div class="container-fluid page-container">
<div class="row">
<div class="col-6 tcontainer-frame">
<div class="tcontainer"><span class="teal-font">Hello. You have landed on the Image Alchemists' web portal. We
welcome
you. Please make your
selection to the right.</span>
</div>
</div>
<div class="col-6 link-container">
<div id="newSolCircle" class="circle">
<p>New Solicitor</p>
</div>
<div id="patronCircle" class="circle">
<p>Patron</p>
</div>
<div id="alchemistCircle" class="circle">
<p>Alchemist</p>
</div>
</div>
</div>
</div>
</div>
</body>
Try this
/*variable declarations*/
:root {
--teal: #37C8AB;
--white: #ffffff;
--black: #000000;
--lilac: #B380FF;
--purple: #7137C8;
--aqua: #008066;
}
/*page body*/
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.page-container {
background: var(--lilac);
margin-top: 10px;
padding-bottom: 5em;
padding-left: 2em;
padding-top: 5.8em;
}
/*Text Conatiner*/
.tcontainer-frame {
background: var(--purple);
border: var(--black) 2px solid;
display: flex;
justify-content: center;
align-items: center;
padding: 1em;
}
.tcontainer {
background: var(--black);
font-size: 24px;
padding: 12em 1em;
text-align: center;
}
.teal-font {
color: var(--teal);
}
/*Link container*/
.link-container {
display: flex;
flex-flow: column wrap;
padding: 4em;
text-align: center;
}
.circle {
align-items: center;
align-self: flex-start;
background: var(--teal);
border-radius: 100%;
display: flex;
/* flex: 1 1 0; */
justify-content: center;
/* margin: 2em;
padding: 1em; */
height: 150px;
width: 150px;
}
#newSolCircle {
display: flex;
justify-content: flex-start;
}
#patronCircle {
display: flex;
justify-content: center;
}
#patronCircle .circle {
background: var(--aqua);
}
#alchemistCircle {
display: flex;
justify-content: flex-end;
}
#alchemistCircle .circle {
background: var(--purple);
}
<body class="bg-dark">
<div class="container-fluid page-container">
<div class="row">
<div class="col-6 tcontainer-frame">
<div class="tcontainer"><span class="teal-font">Hello. You have landed on the Image Alchemists' web portal. We
welcome
you. Please make your
selection to the right.</span>
</div>
</div>
<div class="col-6">
<div class="link-container">
<div id="newSolCircle">
<p class="circle">New Solicitor</p>
</div>
<div id="patronCircle">
<p class="circle">Patron</p>
</div>
<div id="alchemistCircle">
<p class="circle">Alchemist</p>
</div>
</div>
</div>
</div>
</div>
</body>
I have a child div centered vert and horiz inside its parent with content inside centered as well using flex. However, The content and h2 stay side by side centered, I want them to stack.
.jumbotron {
position: relative;
min-height: 600px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
padding: 0;
}
#s-text {
text-align: center;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
width: 70%;
margin: 0 auto;
}
#s-text h2 {
color: #fff;
margin-bottom: 20px;
padding: 0;
}
<div class="jumbotron" style="...">
<div id="s-text">
<h2> the_secondary_title </h2>
<p>multiple lines of content ...</p>
</div>
</div>
Use flex-direction: column;
.jumbotron {
position: relative;
min-height: 400px;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
margin: 0; padding: 0;
}
#s-text {
text-align: center;
height: 100px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 70%;
margin: 0 auto;
}
#s-text h2 {
color: #000;
margin-bottom: 20px; padding: 0;
}
<div class="jumbotron" style="...">
<div id="s-text">
<h2> Heading </h2>
<p>multiple lines of content ...</p>
</div>
</div>