Flexbox Wrap Not Working On 4 Of My Images - html

Hello Im not sure why but for some reason flexbox is not working.
I have 4 images on one section. I added flexbox wrap on the container and I also assigned flex 1
on the children images but for some reason flexbox is not working.
If anyone could help and let me know what I am doing wrong I would really appreciate it.
https://codepen.io/rubenjr005/pen/rNexOZp?editors=0100
HTML CODE
<div id="capabilities" class="bg-dark-02 py-2 angle-top-bottom-right">
<div class="capabilities-title">
<h4 class="section-title text-center">CAPABILITIES</h4>
<h3 class="lead text-center">I DO THINGS LIKE</h3>
</div>
<div class="capabilities-container">
<div class="category">
<div class="content">
<img src="img/graphic-design-icon_03.png" alt="Graphic Design" />
<div class="text-animation">
<h3 class="text-center">GRAPHIC DESIGN</h3>
</div>
</div>
</div>
<div class="category">
<div class="content">
<img src="img/Web-Design-icon_01.jpg" alt="Web Design" />
<div class="text-animation">
<h3 class="text-center">Web Design</h3>
</div>
</div>
</div>
<div class="category">
<div class="content">
<img src="img/web-development-01.png" alt="web Development" />
<div class="text-animation">
<h3 class="text-center">Web Development</h3>
</div>
</div>
</div>
<div class="category category4">
<div class="content">
<img src="img/email-development.png" alt="Email Development" />
<div class="text-animation">
<h3 class="text-center">Email Development</h3>
</div>
</div>
</div>
</div>
</div>
SCSS
#capabilities {
height: 100%;
margin-bottom: 4.5rem;
.capabilities-container {
display: flex;
flex-wrap: wrap;
// min-width: 20%;
.category {
display: flex;
// flex-direction: column;
flex: 1;
padding: 1rem;
align-items: center;
justify-content: center;
min-width: 10rem;
// width: 10rem;
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
img {
position: absolute;
top: 30%;
height: 12rem;
width: auto;
display: block;
// margin: auto;
margin-bottom: 4rem;
opacity: 0.4;
transition: 0.75s;
// padding-bottom: 4rem;
}
.text-animation {
// position: absolute;
text-align: center;
padding-top: 15rem;
transition-duration: 0.75s;
text-align: center;
left: 0;
right: 0;
// background: red;
// margin: auto;
h3 {
color: white;
text-transform: uppercase;
// margin: auto;
}
}
}
}
.category:hover .content img {
opacity: 1;
margin-bottom: 1rem;
// padding-bottom: 0rem;
// padding-bottom: 0rem;
}
.category:hover .content .text-animation {
// opacity: 1.0;
padding-top: 10rem;
}
}
}

You have to get rid of absolute positioning on your img and you'll have to use media queries.
Starting from there, you'll see the flex-wrap: wrap working.
Here is a fork : https://codepen.io/hisato/pen/vYGLLNY?editors=0100
Also, if I may add, as a general advice avoid to transition margin/padding/top/left etc. You should always look for a way to transition the transform property, it will have the best performance.

Related

Why I can't set image on top of div in scroll wrapper div card

I created a cards-based horizontal scroller. And the cards are nicely scrolling inside the wrapper. The issue I'm having is that even after I applied the z-index to our member-owner-card-image, the photos still go under the card when I want to put them on the top of each card.
Is there any solution so that I can add the image on top of the card? I'm trying to fix it, but no solution has been found.
.scrolling-wrapper {
-webkit-overflow-scrolling: touch;
height: 331px;
width: 100%;
padding-inline: 40px;
position: relative;
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
z-index: 0;
}
.scrolling-wrapper::-webkit-scrollbar {
display: none;
}
.card {
width: 100%;
flex: 0 0 auto;
background-color: green;
border-radius: 20px;
position: relative;
margin-right: 10px;
}
.our-member-owner-card-image {
position: absolute;
top: -30px;
z-index: 10;
}
.card-content {
position: absolute;
padding-top: 38px;
}
.member-detail {
padding-top: 55px;
line-height: 1.7;
}
.member-detail h3 {
text-align: center;
color: #263244;
font-weight: 700;
font-family: 'Lato';
}
.member-detail p {
text-align: center;
color: #737C89;
}
.member-description {
padding-inline: 20px;
color: #263244;
line-height: 1.6;
padding-top: 9px;
font-weight: 500;
font-size: 17px;
}
.member-description span {
color: red;
text-decoration: underline;
}
<div class="scrolling-wrapper">
<div class="card">
<div class="our-member-owner-card-image">
<img width="220px" src="https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" />
</div>
<div class="card-content">
<div class="member-detail">
<h3>Sohaib</h3>
<p>Chairman</p>
</div>
<div class="member-description">
Sohaib Ashraf has extensive work experience during his career
of more than 25 years in the financial services sector.<span
>Read more</span
>
</div>
</div>
</div>
<div class="card">
<div class="our-member-owner-card-image">
<img width="220px" src="https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80" />
</div>
<div class="card-content">
<div class="member-detail">
<h3>Sohaib Ashraf</h3>
<p>Chairman</p>
</div>
<div class="member-description">
Sohaib Ashraf has extensive work experience during his career
of more than 25 years in the financial services sector.<span
>Read more</span
>
</div>
</div>
</div>
</div>
You could add the image as a background-image to the card. I added few examples how you can use background-image:
.card{
width: 400px;
height: 300px;
margin: 10px;
border-radius: 6px;
background-color: gray;
}
.card-1, .card-2 .image, .card-3 .image{
/* Here, we use background-image to set the image */
background-image: url("https://images.unsplash.com/photo-1661961110144-12ac85918e40?ixlib=rb-4.0.3&ixid=MnwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80");
/* The background should be a cover photo,
so it fills the whole card: */
background-size: cover;
/* We don't want the image to repeat itself */
background-repeat: no-repeat;
/* When the ratio of the image changes, it will zoom into
this point, which we want to happen in the center of the image */
background-position: center;
}
.card-2, .card-3{
display: grid;
grid-template-rows: 1fr 1fr;
}
.card-2 .image{
border-radius: 6px 6px 0px 0px;
}
.card-3{
padding: 10px;
}
/* This is to demonstrate: */
h2{
color: white;
display: flex;
justify-content: center;
font-family: sans-serif;
}
<div class="card-1 card">
<h2>Test title</h2>
</div>
<div class="card-2 card">
<div class="image"></div>
<div class="content">
<h2> Test title</h2>
</div>
</div>
<div class="card-3 card">
<div class="image"></div>
<div class="content">
<h2> Test title</h2>
</div>
</div>

White corners after border-radius

I want to create a card (that is an image and an overlay). The card should be with border-radius. Unfortunately, when I add it in conjunction with overflow-y: hidden, it creates some white pixels on the corners.
I have the following HTML structure and CSS code:
.container {
max-width: 80rem;
padding: 1em;
margin-inline: auto;
}
.works__column {
display: flex;
flex-direction: column;
gap: 2rem;
}
.size {
--size: 0;
width: var(--size);
height: var(--size);
}
.work {
display: grid;
overflow-y: hidden;
border-radius: .5rem;
}
.work__preview,
.work__overlay {
grid-area: 1 / 2;
}
.work__preview img {
--size: 100%;
object-fit: cover;
aspect-ratio: 2 / 1.4;
}
.work__overlay {
align-self: end;
padding-right: 1rem;
display: flex;
gap: 2rem;
justify-content: space-between;
}
.work__title {
font-weight: 600;
line-height: 1.6;
color: var(--white);
padding: .5rem 1rem;
border-start-end-radius: .5rem;
background-color: var(--steel-gray);
}
.work__icon {
flex-shrink: 0;
align-self: center;
margin-bottom: .125rem;
}
<section class="works">
<div class="container">
<div class="works__column">
<div class="works__work work">
<div class="work__preview">
<img class="size" alt="Sports Elements" src="images/works/1.jpg" />
</div>
<div class="work__overlay">
<h3 class="work__title">
Portier - The ultimate templates & components library.
</h3>
<div class="work__icon icon">0</div>
</div>
</div>
<div class="works__work work">
<div class="work__preview">
<img class="size" alt="The Coporate" src="images/works/2.jpg" />
</div>
<div class="work__overlay">
<h3 class="work__title">
The Coporate - Card for Indian Startups
</h3>
<div class="work__icon icon">1</div>
</div>
</div>
<div class="works__work work">
<div class="work__preview">
<img class="size" alt="App Interface" src="images/works/3.jpg" />
</div>
<div class="work__overlay">
<h3 class="work__title">
Components Web App Interface
</h3>
<div class="work__icon icon">2</div>
</div>
</div>
</div>
</div>
</section>
You can see the problem in these images:
However, the last card works as expected. I don't know the reason.
I think the problem is that I applied aspect-ratio with height: 100% on work__preview img. This is required because the parent has a greater hight and the overlay starts to hang from the image.

How can I fix images in flexbox to wrap 2x2? And correct the hover option?

These are my two flexboxes, one for text and the other for category links. I'm trying to lay the category pictures as 2 by 2. I tried to use row wrap, and center the contents, but it didn't work. I also used various methods using containers, but it always ends up 1 x 4... Also, I'm trying to hover option to fit perfectly into the image, but somehow I have the hover background image not perfectly fit with the image although it's height and width is set to 100%.
How can I solve these issues?
.flex-container {
display: flex;
justify-content: center;
flex-direction: row;
width: 800px;
}
.flex-container > div {
margin: 10px;
padding: 20px;
font-size: 20px;
text-align: center;
flex-flow: row wrap;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 1 1 auto;
}
div.two a > img {
padding: 10px;
margin: 10px;
}
a {
text-decoration: none;
}
h1 {
display: block;
font-size: 1.3em;
margin: 0.67em 0;
font-weight: bold;
}
h2 {
display: block;
font-size: 0.8em;
margin: 0.83em 0;
font-weight: bold;
}
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 200%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: darkorchid;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: Black;
font-size: 18px;
position: absolute;
top: 30%;
left: 100%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
<section>
<div class="flex-container">
<div class="one"> <h1> Welcome to Delicious Book store, <br>
where you can find so many delicious food!</h1>
<p> As a specialized book store, we have many cooking books on
holiday specials, vegetarian, desserts and cultural cuisines!</p>
</div>
<div class="two"> <h2> Shop By Category </h2>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Holiday</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Dessert</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Vegetarian</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Cultural Cuisine</div>
</div></a>
</div>
</div>
</div>
</section>
I've wrapped your boxes with flex container, and change some css regards width of the boxes and their content. Also added width: 100% to your .flex-container.
.flex-container {
display: flex;
justify-content: center;
flex-direction: row;
width: 100%;
}
.flex-container > div {
margin: 10px;
padding: 20px;
font-size: 20px;
text-align: center;
flex-flow: row wrap;
width: 500%;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 1 1 auto;
}
a {
text-decoration: none;
}
h1 {
display: block;
font-size: 1.3em;
margin: 0.67em 0;
font-weight: bold;
}
h2 {
display: block;
font-size: 0.8em;
margin: 0.83em 0;
font-weight: bold;
}
.container {
position: relative;
width: calc(50% - 20px);
margin: 10px;
}
.image {
display: block;
width: 100%;
height: 100%;
min-height: 75px;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: darkorchid;
min-height: 75px;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: Black;
font-size: 18px;
position: relative;
text-align: center;
padding: 10px;
}
.images-container{
display: flex;
flex-wrap: wrap;
}
<section>
<div class="flex-container">
<div class="one"> <h1> Welcome to Delicious Book store, <br>
where you can find so many delicious food!</h1>
<p> As a specialized book store, we have many cooking books on
holiday specials, vegetarian, desserts and cultural cuisines!</p>
</div>
<div class="two"> <h2> Shop By Category </h2>
<div class="images-container">
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Holiday</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Dessert</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Vegetarian</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Cultural Cuisine</div>
</div></a>
</div>
</div>
</div>
</div>
</section>

column image behave as background image

I have two columns using flexbox but does not have to use flexbox. just using it at the moment but am open to other options. The left side is content with a width of 450px and the right column I have an image that needs to behave as a background image but not use css background property. Is there a way to set the image size / image column and have it overflow out of containers and not push the left column content?
setting container widths and using relative positioning but not scaling or behaving as I would like
.row--flex {
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
width: 100%;
margin: 0;
}
.content-col--450 {
max-width: 450px;
}
.content-col {
margin-bottom: auto;
margin-top: 97px;
padding-bottom: 20px;
}
.image-col {
padding-left: 10px;
}
}
.image {
width: 100%;
height: auto;
}
<div class="container container--outer">
<div class="row--flex">
<!--content-->
<div class="content-col content-col--450">
<div class="title-row">
<h2>
testing h2
</h2>
</div>
<div class="content-row">
<p class="p-margin-bottom">
testing P
</p>
<p class="lead">
download test
</p>
<button class="button--arrow">
<span class="button--text">download now</span>
</button>
</div>
</div>
<!--end content-->
<!--image-->
<div class="image-col">
<img src="/img/right-image.png" alt="right column image" class="image-test">
</div>
<!--end image-->
</div>
column 450 stay in place and image overflow out of containers and behave as BG image
You need something like this?
.row--flex {
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
width: 100%;
margin: 0;
}
.content-col--450 {
/* max-width: 450px; */
flex-basis: 450px;
}
.content-col {
margin-bottom: auto;
margin-top: 97px;
padding-bottom: 20px;
}
.image-col {
position: relative;
flex-basis: 450px;
align-self: stretch;
padding-left: 10px;
}
.image-test {
position: absolute;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
object-fit: cover;
}
.image {
width: 100%;
height: auto;
}
<div class="container container--outer">
<div class="row--flex">
<div class="content-col content-col--450">
<div class="title-row">
<h2>
testing h2
</h2>
</div>
<div class="content-row">
<p class="p-margin-bottom">
testing P
</p>
<p class="lead">
download test
</p>
<button class="button--arrow">
<span class="button--text">download now</span>
</button>
</div>
</div>
<div class="image-col">
<img class="image-test" src="https://picsum.photos/536/354" alt="right column image">
</div>
</div>
</div>

My Div does not React to Position: Absolute With The Container Div set to Position: Relative

This should be fairly simple, however I am stumped as to why it is not working. The div (logo-and-text) inside the container (logo-wrapper) does not want to work with position absolute and the parent as position relative. If I do the individual image inside the div or the text it works.
I've tried setting the height of the container, setting margins to zero, checked in chrome dev tools.
<section id="contact-me-section">
<div id="contact-me-section-wrapper">
<div id="have-a-question-wrapper">
<h2 class="contact-h2">HAVE A QUESTION?</h2>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/location.png" alt="">
<p class="contact-p">Dayton, Ohio</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/phone.png" alt="">
<p class="contact-p">( 937 ) 336-9359</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/email.png" alt="">
<p class="contact-p">contact#ryanjthacker.com</p>
</div>
</div>
<div id="logo-wrapper">
<div id="logo-and-text">
<img src="images/logo.png" alt="">
<p>Copyright © 2019 Ryan Thacker - All rights reserved</p>
</div>
</div>
<div id="connect-with-me-wrapper">
<h2 class="contact-h2">CONNECT WITH ME</h2>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/facebook_white.png" alt="">
<p class="contact-p">Facebook</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/linkedin_white.png" alt="">
<p class="contact-p">LinkedIn</p>
</div>
<div class="connect-with-me-image-wrapper">
<img class="contact-img" src="images/github_white.png" alt="">
<p class="contact-p">GitHub</p>
</div>
</div>
</div>
</section>
#contact-me-section {
color: white;
background-color: black;
height: auto;
width:100%;
}
#contact-me-section-wrapper {
display: flex;
text-align: center;
justify-content: center;
}
#have-a-question-wrapper {
display: flex;
flex-direction: column;
margin-bottom: 100px;
}
#logo-wrapper {
margin-left: 150px;
margin-right: 150px;
position: relative;
height: 100%;
}
#logo-and-text {
position: absolute;
bottom: 0;
}
#logo-wrapper img {
width: 116px;
margin: 10px;
}
#connect-with-me-wrapper {
display: flex;
flex-direction: column;
margin-bottom: 100px;
}
.contact-h2 {
font-size: 17px;
margin: 20px;
padding-top: 60px;
padding-bottom: 30px;
text-align: left;
}
.contact-p {
color: #989898;
margin-top:auto;
margin-bottom:auto;
font-size: 15px;
}
.contact-img {
width: 60px;
margin: 20px;
}
.connect-with-me-image-wrapper {
display: flex;
flex-direction: row;
}
I believe I have solved it, its due to using flex box. The solution is a much easier and flexible way to do it.
Instead I just used align-self: flex-end; to the container.