I am very new to html and css. I do know that in my text editor (brackets) the text changes color for keywords, but the "space-between" is not being recognized despite it being one of the choices. The other ones work. (like "center")
Basically what i'm trying to do is spread out my 3 images horizontally across the page when the page is at least 768px. Here is a portion of my index:
<main class="main-area">
<section class="box">
<article class="boxes">
<a href="#">
<figure class="featured-image">
<img src="images/single-blue.jpg">
<div class="box-text">
<h2 class="box-title">Blue Firework</h2>
<p class="box-blurb">Image subtext</p>
</div>
</figure></a>
</article>
<article class="boxes">
<a href="#">
<figure class="featured-image">
<img src="images/single-purple.jpg">
<div class="box-text">
<h2 class="box-title">Purple Firework</h2>
<p class="box-blurb">Image subtext</p>
</div>
</figure></a>
</article>
<article class="boxes">
<a href="#">
<figure class="featured-image">
<img src="images/single-orange.jpg">
<div class="box-text">
<h2 class="box-title">Orange Firework</h2>
<p class="box-blurb">Image subtext</p>
</div>
</figure></a>
</article>
</section>
</main>
<!-- Close the main section -->
I think normally people combine their stylesheets but my teacher wants me to do them separate. Here is a css file:
/*
primary style sheet
*/
#import url('CSS/accessibility.css');
#import url('CSS/reset.css');
#import url('CSS/typography.css');
#import url('CSS/navigation.css');
#import url('CSS/masthead.css');
#import url('CSS/banner.css');
#import url('CSS/boxes.css');
#import url('CSS/levels.css');
here is another css file:
/******** Boxes Stylesheet ********/
.box{
margin: 0 0 1em;
border-bottom: 1px solid #000;
}
.box img {
border: 2px solid #000;
}
.box-title {
font-family: 'Nunito', sans-serif;
font-weight: 300;
color: black;
padding: 0;
}
.box p {
font-family: 'Nunito', sans-serif;
color: black;
font-size: 1.2em;
}
.box a {
color: #000;
text-decoration: none;
display: block;
padding: .25em;
}
#media screen and (min-width: 768px){
.boxes {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.box {
width: calc(33.333333% - .5em);
}
}
The text is white (not recognized) after justify-content: and also after Flex-wrap:
Thank you for your time. (first post so tell me if I posted wrong)
Your selectors are inverted in the CSS media query.
Change:
#media screen and (min-width: 768px){
.boxes {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.box {
width: calc(33.333333% - .5em);
}
}
For:
#media screen and (min-width: 768px){
.box {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.boxes {
width: calc(33.333333% - .5em);
}
}
Code Snippet:
/******** Boxes Stylesheet ********/
.box {
margin: 0 0 1em;
border-bottom: 1px solid #000;
}
.box img {
border: 2px solid #000;
}
.box-title {
font-family: 'Nunito', sans-serif;
font-weight: 300;
color: black;
padding: 0;
}
.box p {
font-family: 'Nunito', sans-serif;
color: black;
font-size: 1.2em;
}
.box a {
color: #000;
text-decoration: none;
display: block;
padding: .25em;
}
#media screen and (min-width: 768px) {
.box {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.boxes {
width: calc(33.333333% - .5em);
}
}
<main class="main-area">
<section class="box">
<article class="boxes">
<a href="#">
<figure class="featured-image">
<img src="http://placehold.it/100x100">
<div class="box-text">
<h2 class="box-title">
Blue Firework
</h2>
<p class="box-blurb">
Image subtext
</p>
</div>
</figure>
</a>
</article>
<article class="boxes">
<a href="#">
<figure class="featured-image">
<img src="http://placehold.it/100x100">
<div class="box-text">
<h2 class="box-title">
Purple Firework
</h2>
<p class="box-blurb">
Image subtext
</p>
</div>
</figure>
</a>
</article>
<article class="boxes">
<a href="#">
<figure class="featured-image">
<img src="http://placehold.it/100x100">
<div class="box-text">
<h2 class="box-title">
Orange Firework
</h2>
<p class="box-blurb">
Image subtext
</p>
</div>
</figure>
</a>
</article>
</section>
</main>
<!-- Close the main section -->
Not every editor is updated with the latest keywords, don't worry space-between is a valid CSS value for justify-content property. You can check out the accepted values for justify-content here and here.
Related
I'm having trouble getting my grid to display the way i want and i can't see what i've done wrong. Please take a look at this for me.
It was displaying correctly when i was using background-image url() in css but i needed to use image tags because they need to be hyperlinks and i'm pretty sure this was the only way. When i use img tags the pictures were now displaying in their full size and i couldnt get them back to the right scale. and when i wrapped them in anchor tags they stopped displaying in the correct order.
Here's my code
* {
box-sizing: border-box;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0;
}
p {
margin: 0;
font-size: 1.8rem;
}
body {
margin: 0;
padding: 0;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
line-height: 1.5;
}
header {
display: flex;
width: 100%;
justify-content: space-between;
background-color: darkgrey;
padding-right: 5%;
}
header h1 {
background-color: blue;
padding: 1px;
min-width: 20%;
color: yellow;
}
nav {
display: flex;
text-decoration: underline darkblue;
width: 60%;
align-items: center;
justify-content: space-around;
}
nav li {
display: inline;
justify-content: flex-end;
padding-left: 8%;
color: yellow;
}
.heroBanner {
background-image: url("../images/02-hero-bg.jpg");
background-size: cover;
height: 200px;
position: relative;
}
#page-section {
width: 100%;
}
#title {
position: absolute;
bottom: 10%;
right: 10%;
background-color: blue;
color: yellow;
}
/* Put my about stuff here */
#about {
display: flex;
padding: 3%;
}
#about p {
align-items: stretch;
color: yellow;
}
#about-1 {
width: 20%;
border-right: solid 8px darkblue;
}
#about-2 {
width: 80%;
padding-left: 3%;
background-image: url(/my-work/images/Portfolio-avatar.png);
background-size:contain;
background-position: center;
}
#work {
height: 1200px;
display: flex;
padding: 3%;
}
#work-1 {
width: 20%;
border-right: solid 8px darkblue;
}
#work-2 {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-template-areas:
'one one'
'two three'
'four five'
}
.pics {
position: relative;
}
.pic-title {
position: absolute;
bottom: 15%;
background-color: blue;
color: yellow;
}
#big {
grid-area: one;
object-fit: contain;
margin: 10px;
border: solid 4px darkblue;
}
#pic1 {
grid-area: two;
object-fit: contain;
width: 25%;
margin: 10px;
border: solid 4px darkblue;
}
#pic2 {
grid-area: three;
object-fit: cover;
margin: 10px;
border: solid 4px darkblue;
}
#pic3 {
grid-area: four;
object-fit: cover;
margin: 10px;
border: solid 4px darkblue;
}
#pic4 {
grid-area: five;
object-fit: cover;
margin: 10px;
border: solid 4px darkblue;
}
#picture1, #picture2, #picture3, #picture4, #picture5 {
object-fit: cover;
}
#contact {
display: flex;
width: 100%;
display: flex;
padding: 3%;
}
#work-2 {
width: 75%;
}
#contact-1 {
width: 20%;
border-right: solid 8px darkblue;
}
#contact-2 {
width: 80%;
}
#contact-2 ul {
display: flex;
list-style: none;
display: flex;
text-decoration: underline darkblue;
width: 80%;
align-items: center;
justify-content: space-between;
}
<!DOCTYPE html>
<html lang="en-gb">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Lorenzo Francis-Walker // Junior Web Developer</title>
<link rel="stylesheet" href="./css/style.css" />
</head>
<body>
<!-- main logo / nav -->
<header>
<h1>Lorenzo Francis-Walker</h1>
<nav>
<li>About me</li>
<li>Work</li>
<li>Contact Me</li>
</nav>
</header>
<!-- hero banner -->
<section class="heroBanner">
<h2 id="title">Room4Renzo</h2>
</section>
<main class="page-wrapper">
<!-- about me -->
<section class="page-section" id="about">
<div id="about-1">
<h2>About Me</h2>
</div>
<div id="about-2">
<p>My love for computers comes from a fairly young age and is greater than my current experience. I was given an
old PC by a friend that soon stopped working. He had another one that worked but soon after giving that to me
, it too stopped working. I found a pdf of how to build computers for dummies on my phone and used what i had
learned to combine the two PC's parts into one case, and it worked. I had always been interested in technology
but this is where my love for understanding computers and how they work. Once you learn about different types
of hardware theres not many places to go. ie networking, coding, etc. fortunately for me, the depth of the
limited options are vast, so there is alot left for me to learn and I never want my journey to end.</p>
</div>
</section>
<!-- portfolio container -->
<section class="page-section" id="work">
<div id="work-1">
<h2>Work</h2>
</div>
<div id="work-2">
<a href="" target="_blank">
<div id="big" class="pics">
<img src="./images/02-run-buddy.jpg" id="picture1" alt="" class="grid-column-span-2">
<div class="pic-title">
<h2>Run Buddy</h2>
<p>Languages Used</p>
</div>
</div>
</a>
<a href="" target="_blank">
<div id="pic1" class="pics">
<img src="./images/02-portfolio-1.jpg" id="picture2" alt="">
<div class="pic-title">
<h2>LED Wall</h2>
<p>Languages Used</p>
</div>
</div>
</a>
<a href="" target="_blank">
<div id="pic2" class="pics">
<img src="./images/02-portfolio-2.jpg" id="picture3" alt="">
<div class="pic-title">
<h2>Calculator</h2>
<p>Languages Used</p>
</div>
</div>
</a>
<a href="" target="_blank">
<div id="pic3" class="pics">
<img src="./images/02-portfolio-3.jpg" id="picture4" alt="">
<div class="pic-title">
<h2>Pastel Puzzels</h2>
<p>Languages Used</p>
</div>
</div>
</a>
<a href="" target="_blank">
<div id="pic4" class="pics">
<img src="./images/02-portfolio-4.jpg" id="picture5" alt="">
<div class="pic-title">
<h2>Surf Report</h2>
<p>Languages Used</p>
</div>
</div>
</a>
</div>
</section>
<!-- contact -->
<section class="page-section contact" id="contact">
<div id="contact-1">
<h2>Contact Me</h2>
</div>
<div id="contact-2">
<ul>
<li>Email: Lorenzo.afw#gmail.com</li>
<li>Github: Room4Renzo </li>
</ul>
</div>
</section>
</main>
</body>
</html>
i tried manually resizing, using object-fit as i saw in another answer, i tried different amount of columns for the grid, same for the rows. i can;t find where my mistake is. appreciate any help. Thanks
I've been asked to design this section of a webpage from figma
Using the figma tools I can see that it is a card of 453 x 512 px and has a padding of 30px on top left and bottom and image is 393 x280 px . There is a 30px margin between the card image and card body after which it is a standard h1 paragraph and link tag. The following is my code implementation.
.blog {
display: flex;
flex-direction: column;
align-items: center;
}
.blog .icons {
display: flex;
flex-direction: row;
}
.card {
width: 453px;
height: 512px;
padding: 30px;
}
<section class="blog">
<h1>We have Most of Popular Departments</h1>
<div class="icons">
<div class="card">
<img src="./assets/ai.svg" alt="image1" class="top" />
<h3>Artificial Intelligence</h3>
<p>
Assertively parallel task synergistic deliverables after high-quality.
</p>
Learn More
</div>
<div class="card">
<div class="card-top">
<img src="./assets/civil.svg" alt="image1" />
</div>
<div class="card-body">
<h3>Civil Engineering</h3>
<p>
Assertively parallel task synergistic deliverables after high-quality.
</p>
Learn More
</div>
</div>
<div class="card">
<img src="./assets/business.svg" alt="image1" class="top" />
<h3>Business Strategy</h3>
<p>
Assertively parallel task synergistic deliverables after high-quality.
</p>
Learn More
</div>
</div>
<button class="btn btn-secondary">View All Departments</button>
</section>
This what my card looks like:
I figured out a solution and it works pretty well. Here is the code.
<div class="cards">
<div class="card">
<img src="/Untitled.png" alt="" />
<div class="container">
<h1>Artificial Intelligence</h1>
<p>
Assertively parallel task synergistic deliverables after
high-quality.
</p>
<a href="#"
>Learn More <i class="fa-solid fa-arrow-right-long"></i
></a>
</div>
</div>
<div class="card">
<img src="/Untitled.png" alt="" />
<div class="container">
<h1>Artificial Intelligence</h1>
<p>
Assertively parallel task synergistic deliverables after
high-quality.
</p>
<a href="#"
>Learn More <i class="fa-solid fa-arrow-right-long"></i
></a>
</div>
</div>
<div class="card">
<img src="/Untitled.png" alt="" />
<div class="container">
<h1>Artificial Intelligence</h1>
<p>
Assertively parallel task synergistic deliverables after
high-quality.
</p>
<a href="#"
>Learn More <i class="fa-solid fa-arrow-right-long"></i
></a>
</div>
</div>
</div>
In styles.css
.cards {
display: flex;
}
.cards .card {
margin-right: 31px;
}
.cards .card:last-child {
margin-right: 0px;
}
.card {
height: 512px;
width: 453px;
padding: 30px;
border-radius: 20px;
transition: 0.3s all ease-in;
}
.card:hover {
box-shadow: 0px 4px 4px #2b2a2a;
}
.card img {
width: 393px;
height: 280px;
border-radius: 20px 20px 0 0;
}
.card h1 {
font-weight: 700;
font-size: 24px;
line-height: 34px;
}
.card p {
font-size: 1.125rem;
overflow: auto;
color: #6f6f76;
max-width: 393px;
}
.card a {
text-decoration: none;
color: #ffa502;
}
Output looks like this :
Now I have encountered a new problem. When I am building out the entire container whose specification is as follows :
The h1 and cards are enclosed in a container of 1421 x 698 px and there is a h1 which is centered in the container with a dimension of 443 x116 px. Now if I want to apply a height and width to a inline element I should set it as display:inline-block and apply height and width properties. But when I do so this happens :
Why is the width and height of a h1 element affecting the elements of card ?
HTML Code:
<section class="cards-container">
<h1>We have most popular departments</h1>
<div class="cards">...</div>
</section>
Styles.css :
/* Cards Container */
.cards-container {
width: 1421px;
height: 698px;
/* display: flex;
flex-direction: column; */
}
.cards-container h1 {
font-size: 40px;
display: block;
width: 443px;
height: 116px;
align-self: center;
text-align: center;
}
currnet result
I am attempting to bottom align the images using flexbox, but my current code is not working as expected.
I thought I can use "align-self" on the image divs to achieve this alignment, but the result is still the same.
What is the best approach to bottom align the images? (desired result at the bottom)
HTML:
<picture>
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-1440.svg" media="(min-width: 1440px)">
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-1024.svg" media="(min-width: 1024px)">
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-768.svg" media="(min-width: 768px)">
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-425.svg">
<!--425px-->
<img class="hs-xmasTree-divider-special" src="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-1024.svg" alt="tree-page-divider">
</picture>
<!--Storage Guide Section-->
<h2>Storing</h2>
<p>
Putting away one of our trees is as simple as assembly.
</p>
<div class="storage-steps-outer">
<div class="storage-steps-inner">
<div>
<h4>Step 1</h4>
<p>
Fold trips along the axis of the branch two at a time.
</p>
</div>
<div class="storage-steps-img">
<img>
</div>
</div>
<div class="storage-steps-inner">
<div>
<h4>Step 2</h4>
<p>
Disconnect each pole section.
</p>
</div>
<div class="storage-steps-img">
<img>
</div>
</div>
<div class="storage-steps-inner">
<div>
<h4>Step 3</h4>
<p>
Nest each section and branches into one of our storage bags.
</p>
</div>
<div class="storage-steps-img">
<img>
</div>
</div>
</div>
CSS:
/*--- ---MOBILE STYLES--- ---*/
.hs-xmasTree-editorial{
margin: 18px 0 0 0;
padding: 0;
}
.hs-xmasTree-editorial h1{
font-size: 30px;
color: #008073;
}
.hs-xmasTree-editorial h2{
font-size: 28px;
color: #008073;
}
.hs-xmasTree-editorial h3{
font-size: 24px;
color: black;
}
.hs-xmasTree-editorial h4{
font-size: 20px;
color: black;
}
.hs-xmasTree-editorial p{
font-size: 18px;
}
.hs-xmasTree-editorial .hs-xmasTree-small-text{
font-size: 14px;
}
.hs-xmasTree-editorial a:link {
color: #1253ad;
text-decoration: none;
}
.hs-xmasTree-editorial a:visited {
color: #1253ad;
}
.hs-xmasTree-editorial a:hover {
color: #000;
text-decoration: underline;
}
.hs-xmasTree-editorial a:active {
color: #1253ad;
}
/*SECTION DIVIDER*/
.hs-xmasTree-divider{
width: 100%;
margin-top: 15px;
margin-bottom: 16px;
}
.hs-xmasTree-divider-special{
width: 100%;
margin-top: 0px;
margin-bottom: 16px;
}
/*Storage Section*/
.storage-steps-outer {
display: flex;
flex-direction: column;
}
.storage-steps-img {
background-color: gray;
width: 100%;
height: 200px;
margin-bottom: 8px;
}
/*Tablet Styles*/
#media only screen and (min-width: 768px) {
/*Desktop Styles*/
#media only screen and (min-width: 1024px) {
/*Tree Width Section*/
/*Storing Section*/
.storage-steps-outer{
display: flex;
flex-flow: row;
}
.storage-steps-inner{
display: flex;
flex-direction: column;
padding: 8px;
flex: 1;
}
.storage-steps-img {
align-self: flex-end;
}
View my codepen: https://codepen.io/mrcrumer/pen/RwgRKor
Desired Result Layout
Use margin
.storage-steps-img {
margin-top: auto;
}
Codepen Link
/*SECTION DIVIDER*/
.hs-xmasTree-divider {
width: 100%;
margin-top: 15px;
margin-bottom: 16px;
}
.hs-xmasTree-divider-special {
width: 100%;
margin-top: 0px;
margin-bottom: 16px;
}
/*Storage Section*/
.storage-steps-outer {
display: flex;
flex-direction: column;
}
.storage-steps-img {
background-color: gray;
width: 100%;
height: 200px;
margin-bottom: 8px;
}
/*Desktop Styles*/
#media only screen and (min-width: 1024px) {
/*Tree Width Section*/
/*Storing Section*/
.storage-steps-outer {
display: flex;
flex-flow: row;
}
.storage-steps-inner {
display: flex;
flex-direction: column;
padding: 8px;
flex: 1;
border: 1px solid red;
}
.storage-steps-img {
margin-top: auto;
}
<picture>
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-1440.svg" media="(min-width: 1440px)">
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-1024.svg" media="(min-width: 1024px)">
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-768.svg" media="(min-width: 768px)">
<source srcset="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-425.svg">
<!--425px-->
<img class="hs-xmasTree-divider-special" src="https://storage.googleapis.com/img.triggermail.io/hammacher/xmas-tree-divider-1024.svg" alt="tree-page-divider">
</picture>
<!--Storage Guide Section-->
<h2>Storing</h2>
<p>
Putting away one of our trees is as simple as assembly.
</p>
<div class="storage-steps-outer">
<div class="storage-steps-inner">
<div>
<h4>Step 1</h4>
<p>
Fold trips along the axis of the branch two at a time.
</p>
</div>
<div class="storage-steps-img">
<img>
</div>
</div>
<div class="storage-steps-inner">
<div>
<h4>Step 2</h4>
<p>
Disconnect each pole section.
</p>
</div>
<div class="storage-steps-img">
<img>
</div>
</div>
<div class="storage-steps-inner">
<div>
<h4>Step 3</h4>
<p>
Nest each section and branches into one of our storage bags.
</p>
</div>
<div class="storage-steps-img">
<img>
</div>
</div>
</div>
I have the following HTML, to show 3 divs beside each other using bootstrap syntax:
.main-background {
background-color: white;
padding-top: 40px;
padding-right: 20px;
padding-bottom: 40px;
padding-left: 20px;
}
.main-Image {
display: flex;
padding-bottom: 40px;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
background-color: white;
box-sizing: border-box;
}
.main-h3 {
align-items: center;
background-color: #fff;
font-family: Lora, sans-serif;
color: #162b3b;
font-size: 24px;
line-height: 1.5em;
font-weight: 400;
text-align: center;
display: flex;
padding: 10px 40px 40px;
-webkit-box-align: center;
box-sizing: border-box;
}
.main-footer {
font-family: 'Source Sans Pro', sans-serif;
color: #162b3b;
font-size: 18px;
line-height: 24px;
text-align: center;
box-sizing: border-box;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<div class="row ">
<div class="col-xl-4 main-background">
<div class="main-Image">
<img src="~/img/How_It_Works_Personalized-1.jpg" loading="lazy" sizes="(max-width: 479px) 93vw, 250px" width="250" />
</div>
<div class="main-h3">
1. Personalized Recommendations
</div>
<div class="main-footer">
Receive practice-specific, data-driven recommendations and care plans
</div>
</div>
<div class="col-xl-4 main-background">
<div class="main-Image">
<img src="~/img/How_It_Works_Personalized-1.jpg" loading="lazy" sizes="(max-width: 479px) 93vw, 250px" width="250" />
</div>
<div class="main-h3">
1. Personalized Recommendations
</div>
<div class="main-footer">
Receive practice-specific, data-driven recommendations and care plans
</div>
</div>
<div class="col-xl-4 main-background">
<div class="main-Image">
<img src="~/img/How_It_Works_Personalized-1.jpg" loading="lazy" sizes="(max-width: 479px) 93vw, 250px" width="250" />
</div>
<div class="main-h3">
1. Personalized Recommendations
</div>
<div class="main-footer">
Receive practice-specific, data-driven recommendations and care plans
</div>
</div>
</div>
Currently the 3 divs will be shown aligned to each other, as follow:
So how I can add some horizontal space between the 3 divs without causing the last div to go to a separate row? Now if I try to add margin-left and margin-right to the middle divs this will cause the last div to move to a new line!
You can use these codes, it will meet what you want. With flex-wrap:nowrap !important;
If you use them it will not go to the bottom line.
.row {
display:flex;
flex-wrap:nowrap !important;
background-color:red;
justify-content:safe center;
}
.main-background {
background-color:#ddd;
padding-top: 40px;
padding-right: 20px;
padding-bottom: 40px;
padding-left: 20px;
margin-left:15px;
margin-right:15px;
width:auto;
}
.main-Image {
display: flex;
padding-bottom: 40px;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
background-color: white;
box-sizing: border-box;
}
.main-h3 {
align-items: center;
background-color: #fff;
font-family: Lora, sans-serif;
color: #162b3b;
font-size: 24px;
line-height: 1.5em;
font-weight: 400;
text-align: center;
display: flex;
padding: 10px 40px 40px;
-webkit-box-align: center;
box-sizing: border-box;
justify-content:center;
}
.main-footer {
font-family: 'Source Sans Pro', sans-serif;
color: #162b3b;
font-size: 18px;
line-height: 24px;
text-align: center;
box-sizing: border-box;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<div class="row ">
<div class="col-xl-4 main-background">
<div class="main-Image">
<img src="https://asia.olympus-imaging.com/content/000107507.jpg" loading="lazy" sizes="(max-width: 479px) 93vw, 250px" width="250" />
</div>
<div class="main-h3">
1. Personalized Recommendations
</div>
<div class="main-footer">
Receive practice-specific, data-driven recommendations and care plans
</div>
</div>
<div class="col-xl-4 main-background">
<div class="main-Image">
<img src="https://asia.olympus-imaging.com/content/000107507.jpg" loading="lazy" sizes="(max-width: 479px) 93vw, 250px" width="250" />
</div>
<div class="main-h3">
1. Personalized Recommendations
</div>
<div class="main-footer">
Receive practice-specific, data-driven recommendations and care plans
</div>
</div>
<div class="col-xl-4 main-background">
<div class="main-Image">
<img src="https://asia.olympus-imaging.com/content/000107507.jpg" loading="lazy" sizes="(max-width: 479px) 93vw, 250px" width="250" />
</div>
<div class="main-h3">
1. Personalized Recommendations
</div>
<div class="main-footer">
Receive practice-specific, data-driven recommendations and care plans
</div>
</div>
</div>
EDIT FOR MOBILE
This allows the bottom line for mobile
#media (max-width:768px) {
.row {
flex-wrap:wrap !important;
}
}
I am creating a portfolio page in which I am showing my 6 projects, 3 in a row using flexbox. The items inside are flowing out of the flexbox even though I have used flex-wrap. I am relatively new to this so I don't know what is happening.
The red border is my flexbox container and it contains six div elements. Inside each div element, there is one image and another div element which is like a caption. Each image is of a different size
HTML Code:
<section id="work">
<h1><u>These are some of my projects</u></h1>
<div id="work-container">
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/tribute.jpg" alt="">
<div id="project-title">Tribute Page</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/random-quote-machine.png" alt="">
<div id="project-title">Random Quote Machine</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/calc.png" alt="">
<div id="project-title">JavaScript Calculator</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/map.jpg" alt="">
<div id="project-title">Map Data Across the Globe</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/wiki.png" alt="">
<div id="project-title">Wikipedia Viewer</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/tic-tac-toe.png" alt="">
<div id="project-title">Tic Tac Toe Game</div>
</div>
</div>
<button id="view-more"></button>
</section>
CSS Used:
#work-container{
display: flex;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
width: 100%;
border: 5px solid red;
}
.work-block{
width: 28%;
margin: 20px;
}
#media (max-width: 1000px) {
.work-block{
width: 45%;
}
}
#work-container img{
height: calc(100% );
width:100%;
margin:0;
padding: 0;
object-fit: cover;
flex:none;
}
There is one particular line which is enabling equal height for all images height: calc(100% );. I don't know how it works, I took it from the internet. It was used to have the equal height for each image.
Also, the bottom and the top margin between blocks is not working.
I want some help in wrapping content inside container properly and understanding how height: calc(100% ); works.
Complete Code: https://codepen.io/tushar_432/pen/poyxmyZ
Don't make the image height:100%, this will make the image take all the space pushing the text outside thus the overflow. Use flexbox to make it fill all the space minuse the text space:
#work-container {
display: flex;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
width: 100%;
border: 5px solid red;
}
.work-block {
width: 28%;
margin: 20px;
}
#media (max-width: 1000px) {
.work-block {
width: 45%;
}
}
.work-block {
display:flex; /* here */
flex-direction:column; /* here */
}
.work-block img {
width: 100%;
margin: 0;
padding: 0;
object-fit: cover;
flex: 1; /* here */
}
<section id="work">
<h1><u>These are some of my projects</u></h1>
<div id="work-container">
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/tribute.jpg" alt="">
<div id="project-title">Tribute Page</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/random-quote-machine.png" alt="">
<div id="project-title">Random Quote Machine</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/calc.png" alt="">
<div id="project-title">JavaScript Calculator</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/map.jpg" alt="">
<div id="project-title">Map Data Across the Globe</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/wiki.png" alt="">
<div id="project-title">Wikipedia Viewer</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/tic-tac-toe.png" alt="">
<div id="project-title">Tic Tac Toe Game</div>
</div>
</div>
</section>
Your caption is overflowing, you can add
display: flex;
flex-direction: column;
to your .work-block
#import url('https://fonts.googleapis.com/css2?family=Alegreya+Sans:wght#400;700&family=Catamaran:wght#400;600&family=Raleway:ital#1&display=swap');
*,*::before,*::after{
margin: 0;
padding: 0;
box-sizing: border-box;
top:0;
}
body{
background-color: bisque;
font-family: 'Catamaran', sans-serif;
text-align: center;
}
#header{
position: sticky;
top:0px;
margin:0;
}
#navbar{
color:white;
width:100%;
display: flex;
background-color:#12343b;
flex-direction: row;
justify-content: flex-end;
padding:18px;
font-family: 'Catamaran', sans-serif;
font-size: x-large;
font-weight: 450;
border-bottom: 2px solid white;
}
.nav-block:hover{
color:#e1b382;
}
.nav-block{
padding:0 20px;
}
#about h1{
font-family: 'Alegreya Sans', sans-serif;
font-weight: 700;
font-size: 65px;
color: #fefefe;
}
#about h3{
font-size:24px;
font-family: 'Raleway', sans-serif;
color: #e1b382;
}
#about{
text-align: center;
padding:250px;
background-color:#2d545e;
color:white;
}
#work{
padding:50px 0;
background-color: #e1b382;
}
#work h1{
font-weight: 600;
font-size: 40px;
color: #12343b;
}
#work-container{
display: flex;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
width: 100%;
border: 5px solid red;
}
.work-block{
width: 28%;
margin: 20px;
display: flex;
flex-direction: column;
}
#media (max-width: 1000px) {
.work-block{
width: 45%;
}
}
#work-container img{
height: calc(100% );
width:100%;
margin:0;
padding: 0;
object-fit: cover;
flex:none;
}
#contact{
padding:150px;
background-color: #2d545e;
}
#contact-container{
display: flex;
}
#footer{
padding:40px;
background-color:#2d545e;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css">
<header id="header">
<nav id="navbar">
<div class="nav-block">About</div>
<div class="nav-block">Work</div>
<div class="nav-block">Contact</div>
</nav>
</header>
<section id="about">
<h1>Hey I am Tushar</h1><br>
<h3>a computers <br>and technology enthusiast</h3>
</section>
<section id="work">
<h1><u>These are some of my projects</u></h1>
<div id="work-container">
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/tribute.jpg" alt="">
<div id="project-title">Tribute Page</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/random-quote-machine.png" alt="">
<div id="project-title">Random Quote Machine</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/calc.png" alt="">
<div id="project-title">JavaScript Calculator</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/map.jpg" alt="">
<div id="project-title">Map Data Across the Globe</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/wiki.png" alt="">
<div id="project-title">Wikipedia Viewer</div>
</div>
<div class="work-block">
<img src="https://raw.githubusercontent.com/freeCodeCamp/cdn/master/build/testable-projects-fcc/images/tic-tac-toe.png" alt="">
<div id="project-title">Tic Tac Toe Game</div>
</div>
</div>
<button id="view-more"></button>
</section>
<section id="contact">
<h1>Let's Work Together</h1>
<p>How do you take your coffee?</p>
<div id="contact-container">
<div class="contact-block">
<i class="fab fa-facebook"></i><span>Facebook</span>
</div>
<div class="contact-block">
<i class="fab fa-github"></i><span>Github</span>
</div>
<div class="contact-block">
<i class="fas fa-hashtag"></i><span>Twitter</span>
</div>
<div class="contact-block">
<i class="fas fa-at"></i><span>Send a mail</span>
</div>
<div class="contact-block">
<i class="fas fa-mobile-alt"></i><span>Call me</span>
</div>
</div>
</section>
<footer id="footer">
<span>**This is just a fake portfolio. All the projects and contact details given are not real.</span>
<span>© Created for freeCodeCamp </span>
</footer>