How to add 2 rows and 3 columns images? - html

My idea of this project is to put 2 rows and 3 columns to put images inside them. I'm using Laravel html Css(without Bootstrap).
What I want looks like this:
Any idea how to start it?

Wrap the images and apply display: grid; to the container.
To have 3 columns, use: grid-template-columns: repeat(3, 1fr);
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
}
.grid img {
width: 100%;
}
<div class="grid">
<img src="https://via.placeholder.com/400x300.jpg">
<img src="https://via.placeholder.com/400x300.jpg">
<img src="https://via.placeholder.com/400x300.jpg">
<img src="https://via.placeholder.com/400x300.jpg">
<img src="https://via.placeholder.com/400x300.jpg">
<img src="https://via.placeholder.com/400x300.jpg">
</div>

Fastest and simplest way to achieve rows and columns is display: flex.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
You could also use grid but grid is more complex and not used as often because it is harder to handle than flex. Flexbox is responsive, adjusts content to screen size so you can expand screen size to see how it works.
Code is very simple. CSS:
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
img {
margin: 5px;
}
<div class="container">
<img src="https://via.placeholder.com/300x300.jpg" />
<img src="https://via.placeholder.com/300x300.jpg" />
<img src="https://via.placeholder.com/300x300.jpg" />
<img src="https://via.placeholder.com/300x300.jpg" />
<img src="https://via.placeholder.com/300x300.jpg" />
<img src="https://via.placeholder.com/300x300.jpg" />
</div>
https://jsfiddle.net/rpvjo26y/12/

in terms of html structure this is what you need:
<table>
<tr>
<td><img src="https://via.placeholder.com/400x300jpg"></td>
<td><img src="https://via.placeholder.com/400x300jpg"></td>
<td><img src="https://via.placeholder.com/400x300jpg"></td>
</tr>
<tr>
<td><img src="https://via.placeholder.com/400x300jpg"></td>
<td><img src="https://via.placeholder.com/400x300jpg" /></td>
<td><img src="https://via.placeholder.com/400x300jpg"></td>
</tr>
</table>

Related

How to display image side by side in html

For the below code when previewing I'm able to see images only verticallysee attached but want to show horizontally too(depending on the quantity). below three images are considered as one image and that one completes prints/preview next one horizontally
Can someone help me on this?
htp.p('<style>
* {
box-sizing: border-box;
}
.row {
display: flex;
}
/* Create two equal columns that sits next to each other */
.column {
flex: 50%;
padding: 10px;
box-sizing: border-box;
}
</style>
');
FOR x in 1 .. 10
loop
htp.p(' <div class="column">
<div class="row">
<table>
<td>
<tr>
<td>
<img style="text-align: center;" alt="TRENDEST_LOGO"
src="https://lh3.googleusercontent.com/Ifrqww75cpmhI3mYsk1C28vYmlwwOi_VvuTyrH0xBEKPqed56lwrJINLZJNhFJ1zLSPFDg=s170"
width="200" height="50" ></td>
</tr>
<tr>
<td>
<img style="text-align: center;" alt="TRENDEST_BARCODE"
src="https://barcode.tec-it.com/barcode.ashx?data='||htf.escape_sc(bcode) ||'&code=Code128&translate-esc=true&unit=Fit&hidehrt=True&modulewidth=1"
width="200" height="80"></td>
</tr>
<tr>
<td>
<a title="ITEMS">
SHIRT ₹230
</a></td>
</tr>
</td>
</table>
</div>
</div> ');
end loop;
Heres your sample you can play with. hope this will help and let me know. I use flex then put a gap in it and wrap it.
.wrapper {
display: flex;
grid-gap:10px;
flex-wrap: wrap;
}
<div class="wrapper">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTVrUH3Siiaj4-KM-a4ZhfESeNb9ZmocLBJuXVgVZtEfMQLZYt6jxbEuvloqE-aNvy9OCU&usqp=CAU" >
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTVrUH3Siiaj4-KM-a4ZhfESeNb9ZmocLBJuXVgVZtEfMQLZYt6jxbEuvloqE-aNvy9OCU&usqp=CAU" >
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTVrUH3Siiaj4-KM-a4ZhfESeNb9ZmocLBJuXVgVZtEfMQLZYt6jxbEuvloqE-aNvy9OCU&usqp=CAU" >
</div>
Create a div container and then the elements inside should have display: inline-block;

Flexbox Directions and multiple images within

I am attempting to use flex-box within this build; I have attached both the HTML and CSS code portions. I have attempted to get the DIV container to hold 9 images that should flex-wrap: wrap into 3 rows of 3 images. I am sure I am missing something small; but the best I can do is get one long continuous row of all 9 images.
I have tried to watch some videos and make different changes within HTML and CSS with no success; could anyone please point me in the right direction, or point out my mistake please?
Code:
.gallery {
width: 100%;
height: 100vh;
text-align: center;
background-color: rgb(0, 4, 17);
flex-direction: row;
}
.food-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.foodimg {
display: flex;
}
<section class="gallery">
<div>
<h2>OUR FOOD</h2>
<div class="food-container">
<div class="foodimg">
<img src="img/food-avocadotoast.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-burger.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-poutine.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-ribs.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-sandwich.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-sausage.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-steak.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-tacos.jpg" alt="" />
</div>
<div class="foodimg">
<img src="img/food-wings.jpg" alt="" />
</div>
</div>
</div>
</section>
Here, It's best to use grids
.food-container{
display: grid;
grid-template-columns: auto auto auto; /*that should do it*/
}

How can I get zero space between images when I horizontally align them?

How can I adjust the code so that there is no space between each image and also how to keep them from overlapping. I tried to add another image but one ended up overlapping it. I have tried looking it up but no matter what I try it just doesn't work.
.column {
float: left;
width: 33.33%;
padding: 5px;
}
.row::after {
content: "";
display: table;
clear: both;
}
.text {
text-align: center;
}
<!--IMAGES-->
<div class="row">
<div class="column">
<img src="https://i.pinimg.com/originals/a0/4f/0a/a04f0abbac3ebf36f1f302937a45071f.jpg" height="300px" width="300px" alt="" />
</div>
<div class="column">
<img src="https://i.pinimg.com/originals/5f/09/7c/5f097ceb782476bae9dc15ec1dd364b1.jpg" height="300px" width="300px" alt="" />
</div>
<div class="column">
<img src="https://i.pinimg.com/736x/68/c7/9f/68c79f2f9203f086d70e75985bf258f2--funny-pets-funny-animals.jpg" height="300px" width="300px" alt="" />
</div>
</div>
You could use flexbox
<div class="row_flex">
<div class="column_flex">
<img src="https://i.pinimg.com/originals/a0/4f/0a/a04f0abbac3ebf36f1f302937a45071f.jpg"
height="300px" width="300px" alt="" />
</div>
<div class="column_flex">
<img src="https://i.pinimg.com/originals/5f/09/7c/5f097ceb782476bae9dc15ec1dd364b1.jpg"
height="300px" width="300px" alt="" />
</div>
<div class="column_flex">
<img src="https://i.pinimg.com/736x/68/c7/9f/68c79f2f9203f086d70e75985bf258f2--funny-pets-funny-animals.jpg"
height="300px" width="300px" alt="" />
</div>
And the CSS
.row_flex {
display: flex;
justify-content: center;
}
I have changed your class names by adding the word "flex" as it looks like you're using something like Zurb foundation or bootstrap, where you wouldn't want to change the properties of "row" and "column" as the rest of your site will likely depend on them.
If you want images to be a little repsonsive I would suggest the following:
.column {
padding: 5px;
/* flex: 1;
flex-basis: 33%; */
max-width: calc(33vw - 10px);
display: flex;
}
.column img {
max-width: inherit;
}
/* .row::after {
content:"";
// display: table;
clear: both;
} */
.text {
text-align: center;
}
.row {
display: flex;
justify-content: center;
}
<div id="app"></div>
<div class="row">
<div class="column">
<img src="https://i.pinimg.com/originals/a0/4f/0a/a04f0abbac3ebf36f1f302937a45071f.jpg"
alt="" />
</div>
<div class="column">
<img src="https://i.pinimg.com/originals/5f/09/7c/5f097ceb782476bae9dc15ec1dd364b1.jpg"
alt="" />
</div>
<div class="column">
<img src="https://i.pinimg.com/736x/68/c7/9f/68c79f2f9203f086d70e75985bf258f2--funny-pets-funny-animals.jpg"
alt="" />
</div>
Depending on whether or not you want this to run for other people you could make your own image on paint where you combine all 3 of the other images and then create an indirect path by guiding it to your images file. There are better methods if you want to be able to give the code to other people or have it work for other people on a browser involving more difficult code but if this is just going to be displayed on your computer and will not go to the public, I think that this would be much easier than coding the solution. That is, unless you are using bootstrap or another adapter.

can't figure out how align 3 pictures side by side

The photos should look like this:
This is a uni assignment and it’s like my first experience with coding so please try to understand. And I'm pretty sure there are a lot of mistakes so please help me out if you can.
This is my code so far:
.wrapper-home-photo {
width: 100%;
height: auto;
display: flex;
flex-direction: row;
background-color: #1d1d1e;
padding: 100px;
<div class="wrapper-home-photo">
<figure>
<img src="./src/imgs/home-photos/strangerthings-home1.jpg" width="540" height="330" />
</figure>
</div>
<div class="wrapper-home-photo">
<figure>
<img src="./src/imgs/home-photos/strangerthings-home2.png" width="400" height="220" />
</figure>
</div>
<div class="wrapper-home-photo">
<figure>
<img src="./src/imgs/home-photos/strangerthings-home3.jpg" width="540" height="330" />
</figure>
</div>
this may help you
<div class="wrapper-home-photo">
<figure>
<img src="./src/imgs/home-photos/strangerthings-home1.jpg" width="540" height="330" />
</figure>
<figure>
<img src="./src/imgs/home-photos/strangerthings-home2.png" width="400" height="220" />
</figure>
<figure>
<img src="./src/imgs/home-photos/strangerthings-home3.jpg" width="540" height="330" />
</figure>
</div>
Put all the images into one centralized div with the class block. From here, you can use display: grid to align all the contents of the div into a grid. Then just do grid-template-columns: 1fr 1fr 1fr; to create 3 columns, each 1fr being 1 fraction of the div, and since you have three images you will need 3 columns. You can use grid-gap: 20px to add some margins and separation between each image.
.banner {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
width: 100%;
grid-column-gap: 20px;
}
.banner img {
width: 100%;
}
<div class="banner">
<img src="https://www.muralswallpaper.com/app/uploads/Green-Tropical-Plant-Wallpaper-Mural-Plain.jpg">
<img src="https://www.muralswallpaper.com/app/uploads/Green-Tropical-Plant-Wallpaper-Mural-Plain.jpg">
<img src="https://www.muralswallpaper.com/app/uploads/Green-Tropical-Plant-Wallpaper-Mural-Plain.jpg">
</div>

Expand dynamic grid columns upto row max width?

Greet1ngs, everyone. I'm trying to implement a header on grid which dynamically moves columns to the next row on smaller screens. I use the following string to build it:
grid-template-columns: repeat(auto-fit, minmax(max-content, 230px));
It kinda works but on some resolutions columns do not expand to the full width to the right and thus another background (from [body]) becomes visible from underneath. How can I make all columns even to the right end of the screen without mediaquery or calc (will try those if no other way)? Sorry for unprofessional explanation, I'm still new to coding. Screenshot
#charset "utf-8";
.headergrid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(max-content, 230px));
margin-top: -8px;
margin-left: -8px;
margin-right: -8px;}
.headergrid > div {
background-color: #191D1F;}
<body style="background-color:#1ba6fc;">
<div class="headergrid">
<div class="location">
<img src="clipart-map-location-11.png" alt="location" width="20" height="20" class="locicon"><span style="color:#E2E4C9">Москва, ул Хабаровская, 2. Cр-Вс с 12 до 18.</span>  
</div>
<div class="element">
<img src="phngrn.png" width="25" height="25" alt="phone" class="phonicon">+7(977)8844-922  
</div>
<div class="element">
<img src="hiclipart.com (11).png" width="30" height="20" alt="mail" class="mailicon"/>mail#zvteh.ru    
</div>
<div class="element">
</div>
<div class="social">
<img src="hiclipart.com.png" width="40" height="30" alt="whatsapp" class="whappicon">  
<img src="hiclipart.com (12).png" width="30" height="30" alt="VK.com" class="vkicon">  
<img src="hiclipart.com (14).png" width="27" height="27" alt="Telegram" class="telecon"></div>
</div>
The solution is to put this grid into parent div box with header's background color. It will override main background there and all rows appear having 100% width at all resolutions.