image gallery with flexbox - css

I want to make a small flexbox gallery of images with inconsistent height.
Desired result using grid:
Current result with flexbox:
.
This content belongs to a course, but I want to do that part with flexbox, as a learning method
container {
width: 90%;
overflow: hidden;
margin: 0 auto;
max-width: 1200px;
padding: 80px 0;
}
.projects {
background-color: #f2f2f2;
overflow: hidden;
margin-bottom: 500px;
}
.projects__grid {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-content: space-between;
height: 550px;
background-color: aqua;
}
.projects__item {
width: 32.8%;
height: 270px;
}
.projects__item--first {
height: 550px;
}
.projects__img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
<section class="projects">
<div class="container">
<h2 class="subtitle">mis proyectos</h2>
<div class="projects__grid">
<article class="projects__item projects__item--first">
<img src="assets/img1.jpg" alt="" class="projects__img">
</article>
<article class="projects__item">
<img src="assets/img2.jpg" alt="" class="projects__img">
</article>
<article class="projects__item">
<img src="assets/img3.jpg" alt="" class="projects__img">
</article>
<article class="projects__item">
<img src="assets/img4.jpg" alt="" class="projects__img">
</article>
<article class="projects__item">
<img src="assets/img5.jpg" alt="" class="projects__img">
</article>
</div>
</div>
</section>

Related

Image goes out of flexbox

I have an image that I want to fit in flexbox.
Card has fixed size, and I want the image to fit in without specifying size but it just ignores flexbox.
.card {
border: 2px solid #072227;
border-radius: 20px;
display: flex;
height: 30vh;
width: 40vw;
}
.card__profile-image {
display: flex;
flex-direction: column;
}
.img__cont img {
height: 100%;
}
.img__cont {
}
.card__name {
min-height: 100%;
}
<div class="card">
<div class="card__section card__profile-image">
<div class="img__cont">
<!-- <div class="image"> -->
<img src="https://scontent.fkiv9-2.fna.fbcdn.net/v/t39.30808-6/317808332_704091791080096_1098720845539800517_n.jpg?_nc_cat=1&ccb=1-7&_nc_sid=09cbfe&_nc_ohc=FFO8v3dmkM8AX_aR9js&_nc_ht=scontent.fkiv9-2.fna&oh=00_AfDQCQcHmZH4QuauHvdxiLEFX0rExv9gMENs8ptsEzdoYg&oe=63DEF9AD" alt="Profile Picture" />
<!-- </div> -->
</div>
<div class="card__name">Alex Hill</div>
</div>
<div class="card__section">
<div class="card__info-top">
<span class="info__top-job">Senior Developer | A1-D</span>
<span class="info__top-contact">alexhill#0001</span>
</div>
<div class="card__info-bottom">6 000$</div>
</div>
</div>
https://codepen.io/watermelon-and-me/pen/jOpQGje
UPD.
Expected result:
https://i.imgur.com/MBRLAMp.png
On .img__cont and .img__cont img, set max-width and max-height to 100% each.
.card {
border: 2px solid #072227;
border-radius: 20px;
display: flex;
height: 30vh;
width: 40vw;
}
.card__profile-image {
display: flex;
flex-direction: column;
}
.img__cont, .img__cont img {
max-width: 100%;
max-height: 100%;
}
.card__name {
min-height: 100%;
}
<div class="card">
<div class="card__section card__profile-image">
<div class="img__cont">
<!-- <div class="image"> -->
<img src="https://scontent.fkiv9-2.fna.fbcdn.net/v/t39.30808-6/317808332_704091791080096_1098720845539800517_n.jpg?_nc_cat=1&ccb=1-7&_nc_sid=09cbfe&_nc_ohc=FFO8v3dmkM8AX_aR9js&_nc_ht=scontent.fkiv9-2.fna&oh=00_AfDQCQcHmZH4QuauHvdxiLEFX0rExv9gMENs8ptsEzdoYg&oe=63DEF9AD" alt="Profile Picture" />
<!-- </div> -->
</div>
<div class="card__name">Alex Hill</div>
</div>
<div class="card__section">
<div class="card__info-top">
<span class="info__top-job">Senior Developer | A1-D</span>
<span class="info__top-contact">alexhill#0001</span>
</div>
<div class="card__info-bottom">6 000$</div>
</div>
</div>

How to align text under a flex image?

I am trying to display some text below the two pictures.
Below the closing divs to be exact. The text is incorrectly displayed on the side of the image.
What am I doing wrong?
It's my first time posting here in a long time so I apologize for any posting mistakes.
/* Helper classes */
.container {
max-width: 1400px;
margin: 0 auto;
width: 90%;
}
.my-sec-1-mt {
margin-top: 4rem;
}
.my-sec-2-mt {
margin-top: 1.8rem;
}
/* Services section */
.rmi-services_services-wrapper display: flex;
flex-direction: column;
gap: 1.8rem;
.rmi-services__service-gallery {
width: 100%;
margin-top: 1rem;
display: flex;
flex-direction: column;
gap: 0.8rem;
}
.rmi-services__service-gallery>.rmi-services__service-visual {
display: flex;
aspect-ratio: 1;
border-radius: 0.5rem;
overflow: hidden;
}
.rmi-services__service-gallery>.rmi-services__service-visual picture {
height: 100%;
}
.rmi-services__service-gallery>.rmi-services__service-visual img {
height: 100%;
object-fit: cover;
object-position: center;
}
<section class="rmi-services my-sec-1-mt">
<div class="container">
<div class="rmi-services__services-wrapper my-sec-2-mt">
<div class="rmi-services__service">
<div class="rmi-services__service-gallery">
<div class="rmi-services__service-visual curve-border">
<picture>
<source srcset="{% static 'image_location" type="image/webp">
<img loading="lazy" class="img-left" src="{% static 'image_location' %}" alt="">
</picture>
</div>
<div class="rmi-services__service-visual curve-border">
<picture>
<source srcset="{% static 'image_location" type="image/webp">
<img loading="lazy" src="{% static 'image_location' %}" alt="">
</picture>
</div>
</div>
</div>
</div>
</div>
</section>

Overflow-x scroll not working on iOS with flex

I already have everything working on the desktop but now I just can't figure out why overflow-x won't work on iOs. I already tried to set the min-width to 0 of all children and also to work it out with table instead of flex.
In the end, it should be a horizontal scroll in the image-container div, that is showing all the images on x-scroll.
As already mentioned, it runs anywhere accept on the iPhone safari browser.
Here is the code so far:
sass:
#main-container {
#image-container {
height: 466px;
width: 95.47vw;
display: flex;
overflow: auto;
-webkit-overflow-scrolling: touch;
#images {
padding-top: 41px;
left: 0;
height: 466px;
width: 1399.8px;
display: flex;
align-items: flex-start;
justify-content: space-between;
border-spacing: 0;
.bodytext {
width: 296.46px;
}
.image {
padding-bottom: 0;
padding-right: 17.5px;
align-self: flex-end;
&:last-child {
padding-right: none;
}
img {
opacity: 100%;
width: 296.46px;
height: auto;
cursor: pointer;
}
img:hover {
opacity: 50%;
}
}
}
}
html:
<div id="main-container">
<div id="image-container">
<div id="images">
<div class="image" id="0-img">
<img ...>
<div class="bodytext">...</div>
<div class="bodytext">...</div>
</div>
<div class="image" id="1-img">
<img ...>
<div class="bodytext">...</div>
<div class="bodytext">...</div>
<div class="image" id="2-img">
<img ...>
<div class="bodytext">...</div>
<div class="bodytext">...</div>
</div>
<div class="image" id="3-img">
<img ...>
<div class="bodytext">...</div>
<div class="bodytext">...</div>
</div>
<img ...>
<div class="bodytext">...</div>
<div class="bodytext">...</div>
</div>
</div>
</div>
Thanks a lot!

How to fix div width using scss (with react)

I want to fix div width (image) and get scroll-bar. But the more add 'div', the smaller width of div in wrapper div area. It doesn't appear scroll-bar.
This is image-wrapper below.
<div className="image-list-wrapper">{imageList}</div>
{imageList} are added by clicking button with 'div'
let imageList;
if(images){
imageList = images
.map((image, i) => {
return(
<div key={i} className="image-list-item">
<img className="image-resize" src={`http://localhost:5000`+image}/>
</div>
)
})
}
and CSS (SCSS)
.image-list-wrapper {
margin: auto;
margin-top: 1.5rem;
width: 95%;
height: 12rem;
border: 1px solid #bcbaba;
overflow-x: auto;
display: flex;
flex-direction: row;
align-items: center;
}
.image-list-item {
float: left;
width: 9rem;
height: 9rem;
margin: 0.5rem;
margin-top: -0.5rem;
}
.image-resize {
width: 100px;
height: 160px;
}
I got result below (screenshot)(please ignore other buttons.)
screen shot
screen shot2
The more images, the smaller images.
I want scroll-bar and fixed width of div items in wrapper div.
Your code will generate something like this:
<div class="image-list-wrapper">
<div key="0" class="image-list-item">
<img class="image-resize" src="https://via.placeholder.com/200x160">
</div>
<div key="1" class="image-list-item">
<img class="image-resize" src="https://via.placeholder.com/200x160">
</div>
<div key="2" class="image-list-item">
<img class="image-resize" src="https://via.placeholder.com/200x160">
</div>
<div key="3" class="image-list-item">
<img class="image-resize" src="https://via.placeholder.com/200x160">
</div>
<div key="4" class="image-list-item">
<img class="image-resize" src="https://via.placeholder.com/200x160">
</div>
<div key="5" class="image-list-item">
<img class="image-resize" src="https://via.placeholder.com/200x160">
</div>
<div key="6" class="image-list-item">
<img class="image-resize" src="https://via.placeholder.com/200x160">
</div>
</div>
and you should remove float left because you either use floated elements or you use flexbox.
.image-list-wrapper {
margin: auto;
margin-top: 1.5rem;
width: 95%;
height: 12rem;
border: 1px solid #bcbaba;
overflow-x: auto;
display: flex;
flex-direction: row;
align-items: center;
}
.image-list-item {
width: 9rem;
height: 9rem;
margin: 0.5rem;
margin-top: -0.5rem;
}
.image-resize {
width: 100px;
height: 160px;
}
which results into this: Demo here

Flexbox not working properly on chrome

I'm using the following code to display 5 images (without the use of background) distributed evenly across a container and with an equal height equivalent to the tallest image (although I wonder if it would be possible to do this with the shortest one). Applying flex: 1; on the image-container gives me the desired effect under firefox, but under chrome the 5 images appear vertically stretched and oversized. The desired effect is to keep every container filled under a given width while minimizing loss of aspect ratio.
Edit: I've loaded this page under both browsers and I do get the effect I wanted although they are rendered differently. Now I need to find what's wrong with my version compared to the one I posted here.
body {
width: 300px;
}
.container {
display: flex;
flex-wrap: wrap;
height: 100%;
width: 100%;
background-color: black;
}
.row1 {
display: flex;
width: 100%;
background-color: blue;
}
.column {
height: 100%;
width: 20%;
display: flex;
flex-flow: column;
position: relative;
background-color: red;
}
.image-container {
overflow: hidden;
display: flex;
flex: 1;
background-color: yellow;
}
img {
width: 100%;
height: auto;
}
.image-label {
width: 100%;
height: 35px;
display: flex;
background-color: green;
justify-content: center;
}
.row2 {
display: flex;
width: 100%;
flex-flow: row wrap;
background-color: cyan;
height: 20px;
}
<div class="container">
<div class="row1">
<div class="column">
<div class="image-container">
<img src="http://www.koka.ac.jp/admission/wp-content/themes/admission/assets/img/common/floating-btn-internet.gif">
</div>
<div class="image-label">img1</div>
</div>
<div class="column">
<div class="image-container">
<img src="http://www.moglix.com/themes/et_poostyle/img/offer.jpg">
</div>
<div class="image-label">img2</div>
</div>
<div class="column">
<div class="image-container">
<img src="http://i.imgur.com/slhFy4T.png">
</div>
<div class="image-label">img3</div>
</div>
<div class="column">
<div class="image-container">
<img src="http://alma-sys.com/images/SLIDE%20MENU%20IMG/WEB%20D%20-%20Copy.jpg">
</div>
<div class="image-label">img4</div>
</div>
<div class="column">
<div class="image-container">
<img src="http://amerpages.com/app/webroot/img/items/121/16716/pds/19682_s.jpg">
</div>
<div class="image-label">img5</div>
</div>
</div>
<div class="row2"></div>
</div>

Resources