Responsive group of images not staying in the same line on phone view - html

so i kinda have two problems
i´m trying to make a responsive container of images that when the resolution changes the images stay side by side.
my problem is when i change the resolution to a phone when testing the images show one below the other and one
and one image's width is smaller so the image shows up a bit weird
here's what i tried
html
<div class="container-fluid">
<div class="row">
<div class="col-sm">
<img src="brands/Adidas-Logo.png" alt="" id="brand_img_adidas">
</div>
<div class="col-sm">
<img src="brands/Nike_logo.png" alt="" id="brand_img_nike">
</div>
<div class="col-sm">
<img src="brands/the-north-face-logo-png-8.png" alt="" id="brand_img_north">
</div>
<div class="col-sm">
<img src="brands/tommy-hilfiger-logo-png-transparent.png" alt="" id="brand_img_tommy">
</div>
<div class="col-sm">
<img src="brands/zara-logo-0.png" alt="" id="brand_img_zara">
</div>
</div>
</div>
css
#brand_img_adidas
{
width: 150px;
height: 100px;
max-width: 100%;
margin-left: 10px;
}
#brand_img_nike
{
width: 200px;
height: 100px;
margin-left: 20px;
max-width: 100%;
}
#brand_img_north
{
width: 150px;
height: 150px;
margin-left: 20px;
max-width: 100%;
}
#brand_img_tommy
{
width: 150px;
height: 120px;
margin-left: 20px;
max-width: 100%;
margin-right: 0;
}
#brand_img_zara
{
width: 150px;
height: 150px;
margin-left: 10px;
margin-right: 0;
max-width: 100%;
}

This is not using bootstrap but this should help you get an idea about using flexbox.
So, to stack the images next to each other, we can use display: flex on the parent container.
By default, the flex-direction will be row which means that the child elements will be placed next to each other.
We can also provide flex-wrap: wrap property to make sure that if the elements overflow, it will be moved to next row.
You can read more about flexbox here
.row {
display: flex;
flex-wrap: wrap;
}
.row .col {
margin-right: 5px;
}
<div class="row">
<div class="col">
<img src="https://via.placeholder.com/150" alt="" id="brand_img_adidas">
</div>
<div class="col">
<img src="https://via.placeholder.com/150" alt="" id="brand_img_2">
</div>
<div class="col">
<img src="https://via.placeholder.com/150" alt="" id="brand_img_3">
</div>
<div class="col">
<img src="https://via.placeholder.com/150" alt="" id="brand_img_4">
</div>
<div class="col">
<img src="https://via.placeholder.com/150" alt="" id="brand_img_5">
</div>
</div>

Related

How to create a specific image gallery using css (see details)

Here is a sample image of the layout I am trying to achieve with HTML and CSS:
From what the gallery looks like,
the images are placed in a row
each row fills the width of the container
each image fills the height of the row
The height of each row looks to be slightly different (e.g. min-height: 300px; max-height: 600px;) to accomadate for the different aspect ratios of the image.
I'm trying to build this layout with html and css flexbox, but haven't really gotten too far with it:
.gallery-container {
display: block;
margin: 0 auto;
width: 50%;
}
.gallery-row {
display: flex;
min-height: 300px;
max-height: 500px;
}
.gallery-img {
position: relative;
flex-grow: 1;
max-width: 33.3%;
}
.gallery-img img {
height: 100%;
}
<div class="gallery-container">
<div class="gallery-row">
<div class="gallery-img">
<img src="https://picsum.photos/200/300"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/300/200"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/400/200"/>
</div>
</div>
<div class="gallery-row">
<div class="gallery-img">
<img src="https://picsum.photos/400/300"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/100/200"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/300/200"/>
</div>
</div>
</div>

Float based grid system rendering outside viewport

I set out to create a float based grid system and have added gutters between columns via padding: 0 0.75em; applied to columns with margin-right: -0.75em; and margin-left: -0.75; applied to rows.
When I have a full width container it renders outside the width of the viewport with the horizontal scrollbarr showing.
I want the leftmost and the rightmost element to stick along the edges of the viewport, but still want to preserve the gutters between elements. I must be missing something. Any help would be appreciated, thank you!
Here's CSS followed by HTML:
.container-full {
width: 100%;
}
.row {
margin-right: -0.75em;
margin-left: -0.75em;
}
.row::before,
.row::after {
display: block;
content: "";
clear: both;
}
[class*="column-"] {
float: left;
padding-right: 0.75em;
padding-left: 0.75em;
}
<div class="container-full">
<div class="row">
<div class="column-3">
<div class="exhibition-brief">
<img src="./img/img01.jpg" alt="Image">
</div>
</div>
<div class="column-3">
<div class="exhibition-brief">
<img src="./img/img02.jpg" alt="Image">
</div>
</div>
<div class="column-3">
<div class="exhibition-brief">
<img src="./img/img03.jpg" alt="Image">
</div>
</div>
<div class="column-3">
<div class="exhibition-brief">
<img src="./img/img04.jpg" alt="Image">
</div>
</div>
</div>
</div>
You can achieve this via using CSS Grid and the grid-gap property.
<div class="container">
<img src="https://picsum.photos/1920/1080" alt="">
<img src="https://picsum.photos/1920/1081" alt="">
<img src="https://picsum.photos/1920/1082" alt="">
<img src="https://picsum.photos/1920/1083" alt="">
</div>
.container {
width: 100vw;
height: 100vh;
display: grid;
grid-template-columns: repeat(4,1fr);
grid-gap: 0.75rem;
}
img {
max-width: 100%;
height: 100%;
object-fit: cover;
}

How to resize multiple images side by side to to fit the current screen size?

I have a div with 5 rows and with multiple images in it. The Html looks something like this:
<div id="row3" class="row">
<div id="im15" class="column">
<img src="img/img15.jpg" alt="movie">
</div>
<div id="im16" class="column">
<img src="img/img16.jpg" alt="movie">
</div>
<div id="im17" class="column">
<img src="img/img17.jpg" alt="movie">
</div>
<div id="im18" class="column">
<img src="img/img18.jpg" alt="movie">
</div>
<div id="im19" class="column">
<img src="img/img19.jpg" alt="movie">
</div>
<div id="im20" class="column">
<img src="img/img20.jpg" alt="movie">
</div>
<div id="im21" class="column">
<img src="img/img21.jpg" alt="movie">
</div>
</div>
I have them side by side and my css looks like this:
html, body {
background-color: #222222;
overflow: hidden;
}
.column {
float: left;
}
.column img {
width: 200px;
height: 300px;
padding: 1px;
}
.images {
opacity: 0.4;
}
.row {
clear: both;
display: table;
}
It works and displays all images properly stacked with no left space in my screen size laptops, but for bigger screens this fails.
I am not able to understand how can I resize these many images to fit and leave no space for any screen size.
I would appreciate any help.
Try to use grid system.
grid-template-columns defines how many columns you want to divide, in the flowing example I divide 3 columns with the value 1fr 1fr 1fr.
grid-gap defines the gaps between each grids.
More information about css grid system, you can refer to this Youtube video:
https://www.youtube.com/watch?v=jV8B24rSN5o&t=1325s&frags=pl%2Cwn
It's very useful when doing some layouts with CSS.
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 1em;
}
.box {
border: 1px solid teal;
}
.box img {
width: 100%;
height: 100%;
}
<div class="container">
<div class="box">
<img src="" alt="">
</div>
<div class="box">
<img src="" alt="">
</div>
<div class="box">
<img src="" alt="">
</div>
<div class="box">
<img src="" alt="">
</div>
<div class="box">
<img src="" alt="">
</div>
<div class="box">
<img src="" alt="">
</div>
<div class="box">
<img src="" alt="">
</div>
</div>
Note : This is code for 3 images side by side horizontally
* {
box-sizing: border-box;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
.row::after {
content: "";
clear: both;
display: table;
}

Html photo gallery - remove space

I have a photo gallery in HTML / CSS and I have a space between 2 photos. I want the space to be like in photo (in left)
.portfolio-img {
width: 45%;
height: 100%;
margin-top: 2rem;
margin-left: 1rem;
}
<div class="container">
<div class="row">
<img src="images/img3.jpg" class="portfolio-img">
<img src="images/img1.jpg" class="portfolio-img">
<img src="images/img2.jpg" class="portfolio-img">
<img src="images/img4.jpg" class="portfolio-img">
</div>
</div>
You can use
.porfolio-img {
width: 45%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
background-size: cover will ensure that the source image covers the area of the img tag.
You are giving height in % please change it to px
.portfolio-img {
width: 45%;
height: 300px; /* ---> give height it as you want */
margin-top: 2rem;
margin-left: 1rem;
}
<div class="container">
<div class="row">
<img src="images/img3.jpg" class="portfolio-img">
<img src="images/img1.jpg" class="portfolio-img">
<img src="images/img2.jpg" class="portfolio-img">
<img src="images/img4.jpg" class="portfolio-img">
</div>
</div>
There is a nice example in w3school website
https://www.w3schools.com/css/tryit.asp?filename=trycss3_flexbox_image_gallery
In summary you use display flex and divide the images into columns
This is the result for your case
.container {
display: flex;
flex-wrap: wrap;
}
.row {
flex: 50%;
max-width: 50%;
}
.portfolio-img {
width:100%;
vertical-align: middle;
}
<div class="container">
<div class="row">
<img src="https://images.pexels.com/photos/1089562/pexels-photo-1089562.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" class="portfolio-img filter development">
<img src="https://images.pexels.com/photos/1037996/pexels-photo-1037996.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" class="portfolio-img filter marketing">
</div>
<div class="row">
<img src="https://images.pexels.com/photos/1037995/pexels-photo-1037995.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" class="portfolio-img filter development">
<img src="https://images.pexels.com/photos/1037999/pexels-photo-1037999.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" class="portfolio-img filter design">
</div>
</div>

resizes image inside col-md-12 class

I created a responsive site but some of the images dont resize as I want them to.
See this screenshot:
#img1 {
width: 250px;
height: auto;
margin: auto;
display: block;
background-size: 20%;
}
<div class="row">
<div class="col-md-6" id="mision">
<img src="imagenes/MISION.png" id="img1">
</div>
<div class="col-md-6" id="vision">
<img src="imagenes/VISION.png" id="img2">
</div>
<div class="col-md-12" id="servicios">
<img src="imagenes/SERVICIOS.png" id="img3">
</div>
</div>
You're using a fixed width in the CSS for your image element, try changing to a percentage width, e.g.:
#img1{
width: 80%;
height: auto;
margin: auto;
display: block;
background-size:20%;
}
Then the width of the image should resize with your column.