How can i create a padding between images in splited div? - html

I split my container and put an image in each of them but when I add padding: 0 25px its not creating space between images. So is there any way to put 25px padding between photos/divs?
I tried to put margin and paddings in both html and CSS
* {
box-sizing: border-box;
}
.col-1-3 {
width: 33.333%;
float: left;
padding: 0 25px;
}
.test {
margin: 0 auto;
width: 1700px;
border: 1px solid red;
}
.clearfix:after,
.clearfix:before {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
<div class="test clearfix">
<div class="col-1-3">
<img src="https://picsum.photos/560" alt="">
</div>
<div class="col-1-3">
<img src="https://picsum.photos/560" alt="">
</div>
<div class="col-1-3">
<img src="https://picsum.photos/560" alt="">
</div>
</div>

The float/clearfix hack shouldn't be used anymore. Use flex or grid to make your layout more "up to date".
Here is a solution with grid that creates a 25px gap between images:
* {
box-sizing: border-box;
}
.col-1-3 img {
display: block;
width: 100%;
}
.test {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 25px;
margin: 0 auto;
width: 1700px;
}
<div class="test">
<div class="col-1-3">
<img src="https://picsum.photos/500" alt="">
</div>
<div class="col-1-3">
<img src="https://picsum.photos/500" alt="">
</div>
<div class="col-1-3">
<img src="https://picsum.photos/500" alt="">
</div>
</div>

Related

How to make the grid columns smaller and the same size?

I have a gallery of gifs and I put them in a grid, here's the image. I want to make the columns smaller like at least 5 images in one row, and in the same size(in the image you can see there's a difference in height).
here's the css:
.gallery {
margin: 5px;
border: 1px solid #ccc;
}
.gallery:hover {
border: 1px solid #777;
}
.gallery img {
width: 100%;
height: 100%;
object-fit:cover;
}
.container {
background-color: #222324;
padding: 20px;
margin: 20px;
overflow: auto;
text-align: center;
}
and the html:
<div class='container' style='display: grid;grid-template-columns: auto auto auto;'>
<div class='gallery'>
<img src=GIFURL>
</div>
<div class='gallery'>
<img src=GIFURL2>
</div>
...
</div>
thanks
You can have 5 images in a row with help of grid-template-columns: repeat(5, 1fr); It will accommodate 5 elements in a row all having the same width.
you can control the height of images based on viewport height by putting height: calc(100vh /3); on gallery image.
.gallery {
margin: 5px;
border: 1px solid #ccc;
}
.gallery:hover {
border: 1px solid #777;
}
.gallery img {
width: 100%;
height: calc(100vh /3);
object-fit:cover;
}
.container {
display: grid;
grid-template-columns: repeat(5, 1fr);
background-color: #222324;
padding: 20px;
margin: 20px;
overflow: auto;
text-align: center;
}
<div class='container'>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/200">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/400">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/300">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/300">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/200">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/100">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/500">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/300">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/300">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/100">
</div>
<div class='gallery'>
<img src="https://picsum.photos/id/237/200/100">
</div>
</div>

Center the HTML images

I want the two images being centered. See https://prnt.sc/qxaapc for a visual representation of what I want.
Code:
* {
box-sizing: border-box;
}
.column {
float: left;
width: 28%;
height: 28%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
<div class="row" align="center">
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" style="width:100%">
</div>
</div>
try this
.row
{
display: flex;
justify-content: center;
}
Instead of using floats you could better use flexbox. See https://css-tricks.com/snippets/css/a-guide-to-flexbox/ for all the different options you have with this.
Working example:
/* General */
* {
box-sizing: border-box;
}
img {
width: 100%;
height: auto;
}
/* Specific */
.row {
display: flex;
justify-content: center;
}
.column {
flex: 0 1 28%;
padding: 5px;
}
<div class="row">
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="Snow">
</div>
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
</div>
Small tip: try to avoid inline styling like style="width: 100%" on the images.
class="column" for the inner sections is causing the images to appear side-by-side.
These 2 changes can make the images appear one below the other, in a center justified manner:
Specify 'align=center' for the top level section.
Specify 'class=row' for the sections that show the images.
Here is the working solution:
<div align="center">
<div class="row">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt="Snow" style="width:300px">
</div>
<div class="row">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" style="width:300px">
</div>
</div>
Try with this:
.column {
width: 28%;
height: 28%;
padding: 5px;
display: inline-block;
margin-right: 15px;
text-align: left;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 28%;
height: 28%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row {
display: flex;
justify-content: center
}
<div class="row" align="center">
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" style="width:100%">
</div>
</div>
I just set for .row display: flex; justify-content:center; style
Use display: inline-block; instead of float:left in your .column class
and use width:100% for .row class
* {
box-sizing: border-box;
}
.row{
width: 100%;
}
.column {
display: inline-block;
width: 28%;
height: 28%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
<div class="row" align="center">
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" style="width:100%">
</div>
</div>

How to make responsive 3 image which has different scale?

I'm working in Wordpress and i need to insert 3 image in a row.
I'm using default editor because of my client ask that.
Insert the 3 image html for the page and then give this a little CSS with simple CSS plugin :
It's okay, the 3 image appear in a row, which has 170px height, but when i open this in mobile or tablet the scale isn't responsive.
I try to make container which has 170px height, and put the image them but wasn't working. I try to make #media query but that wasn't work.
Anyone can help me ?
I want if these 3 picture is got ca. 170px and being responsive.
* {
box-sizing: border-box;
}
.tanfolyam-kepek {
float: left;
width: 33.33%;
padding: 10px;
height: 170px;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
<div class="clearfix">
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1-226x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2-300x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek"src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3-300x243.jpg" alt=""/>
</div>
</div>
Responsive images on a row. Verttical and horizontal alignment. No use of clearfix. Cross browser.
<div class="box-container">
<div class="box">
<a href="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1.jpg">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1-226x300.jpg" alt=""/>
</a>
</div>
<div class="box">
<a href="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2.jpg">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2-300x300.jpg" alt=""/>
</a>
</div>
<div class="box">
<a href="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3.jpg">
<img class="tanfolyam-kepek"src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3-300x243.jpg" alt=""/>
</a>
</div>
</div>
with css
* {
box-sizing: border-box;
}
.box-container {
height: 170px; /* height you asked for */
outline: thin dotted grey; /* this outline for test only */
}
#media (max-width: 575.9px) {
.box-container {
height: ...px; /* for mobile, for example 140px */
}
}
.box {
float: left;
width: 33.333%;
height: 100%;
text-align: center; /* horizontal alignment */
}
.box a {
display: block;
/* 5 lines below for vertical alignment */
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.box img {
max-width: 100%;
height: auto; /* responsive image */
max-height: 170px; /* no overflow */
border: 10px solid #fff; /* border used as padding */
}
you can use bootstrap grid to make your images responsive. all you have to do is
<div class="row">
<div class="col-sm-4 col-xs-4>
//your image here
</div>
<div class="col-sm-4 col-xs-4>
//your image here
</div>
<div class="col-sm-4 col-xs-4>
//your image here
</div>
</div>
And avoid using px to specify the size since it is not responsive. Use vh and vw which stand for viewport height and viewport width respectively
.box{
display: inline-block;
width: 31.3%;
height: 200px;
text-align: center;
border: 1px solid #ddd;
padding: 20px 0;
margin: 10px;
}
.box img{
vertical-align: middle;
display: inline-block;
height: 100%;
max-width: none;
width: auto;
}
You can have something like this for have always tree picters in a row.
* {
box-sizing: border-box;
}
.tanfolyam-kepek {
float: left;
width: 33.33%;
padding: 10px;
height: 170px;
object-fit: cover;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
<div class="clearfix">
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc1-226x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek" src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc2-300x300.jpg" alt=""/>
</div>
<div class="box">
<img class="tanfolyam-kepek"src="https://ezoakademia.hu/wp-content/uploads/2018/12/rozsakvarc3-300x243.jpg" alt=""/>
</div>
</div>

Center a div of Images

How can I center a collection of 3 images. I would like the collection to be centered on the webpage. SIDE BY SIDE*. collection of side by side images with spacing.
.column {
float: left;
width: 30.00%;
padding: 5px;
}
/* Clear floats after image containers */
.row::after {
content: "";
clear: both;
display: table;
}
<div class="row">
<div class="column">
<img src="https://cdn.pixabay.com/photo/2017/05/09/21/49/gecko-2299365_1280.jpg" alt="BullishTrade" style="width:100%">
</div>
<div class="column">
<img src="https://cdn.pixabay.com/photo/2017/05/09/21/49/gecko-2299365_1280.jpg" alt="BullishTrade" style="width:100%">
</div>
<div class="column">
<img src="https://cdn.pixabay.com/photo/2017/05/09/21/49/gecko-2299365_1280.jpg" alt="BullishTrade" style="width:100%">
</div>
</div>
Easiest Solution to use Flex.
.row{
display:flex;
justify-content:center; //This will get your images to center.
}
Images width is purposefully reduced to 20%.
.column {
width: 20.00%;
padding: 5px;
}
/* Clear floats after image containers */
.row::after {
content: "";
clear: both;
display: table;
}
.row {
display: flex;
justify-content: center;
}
<div class="row">
<div class="column">
<img src="https://cdn.pixabay.com/photo/2017/05/09/21/49/gecko-2299365_1280.jpg" alt="BullishTrade" style="width:100%">
</div>
<div class="column">
<img src="https://cdn.pixabay.com/photo/2017/05/09/21/49/gecko-2299365_1280.jpg" alt="BullishTrade" style="width:100%">
</div>
<div class="column">
<img src="https://cdn.pixabay.com/photo/2017/05/09/21/49/gecko-2299365_1280.jpg" alt="BullishTrade" style="width:100%">
</div>
</div>
Make sure to check browser Compatibility with Flexbox.
It will work with most of the modern browsers.
One option using Grid:
body {
margin: 0;
height: 100vh;
display: grid;
align-items: center;
justify-content: center;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
/* change as you need */
max-width: 50vw;
}
.image img {
max-width: 100%;
height: auto;
display: block;
}
<div class="wrapper">
<div class="image">
<img src="https://unsplash.it/400" alt="BullishTrade">
</div>
<div class="image">
<img src="https://unsplash.it/400" alt="BullishTrade">
</div>
<div class="image">
<img src="https://unsplash.it/400" alt="BullishTrade">
</div>
</div>

Floating images are not at the same height on relative position

I need a set of icons grouped under a div to appear to the right of my logo (which is located on the top-left corner). I need the logo and all icons to have a position of relative. I am using float:left for both divs, but the second div (the group of icons) appears below the logo and not to its right. I have also tried grouping them under an unordered list and input style="float:left" as HTML, but it does not work either.
Here is the CSS:
div.container {
width: 1111px;
}
#parent {
display: flex;
}
.logo {
float: left;
position: relative;
top: 0px;
margin-left: 0px;
}
#icons {
position: relative;
float: left;
white-space: nowrap;
width: 100%;
display: table;
max-width: 100%;
}
.all-icons {
position: relative;
float: left;
vertical-align: middle;
padding: 15px;
display: table-cell;
}
.all-icons img {
height: auto;
width: auto;
max-height: 77px;
max-width: 100%;
margin: 15px;
}
<body>
<div class="container">
<div id="parent">
<div class="logo"> <img src="http://placehold.it/77" width="27%" height="27%"> </div>
<div id="icons" style="float:left" class="all-icons">
<img src="http://placehold.it/77" width="389" height="317">
<img src="http://placehold.it/77" width="451" height="317">
<img src="http://placehold.it/77" width="427" height="317">
<img src="http://placehold.it/77" width="837" height="317">
<img src="http://placehold.it/77" width="594" height="317">
</div>
</div>
</div>
</body>
Is this what you look for?
div.container {
/* width: 1111px; */
}
#parent {
display: flex;
}
.logo img {
margin: 15px;
}
.all-icons {
white-space: nowrap;
}
.all-icons img {
margin: 15px;
}
<div class="container">
<div id="parent">
<div class="logo">
<img src="http://placehold.it/77/f00" alt="">
</div>
<div id="icons" class="all-icons">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
</div>
</div>
</div>
If you can't use flex, try display: table
div.container {
/* width: 1111px; */
}
#parent {
display: table;
}
.logo {
display: table-cell;
}
.all-icons {
display: table-cell;
}
.logo img {
margin: 15px;
}
.all-icons {
white-space: nowrap;
}
.all-icons img {
margin: 15px;
}
<div class="container">
<div id="parent">
<div class="logo">
<img src="http://placehold.it/77/f00" alt="">
</div>
<div id="icons" class="all-icons">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
<img src="http://placehold.it/77" alt="">
</div>
</div>
</div>
Add #icons { text-align: right; }, i think this will help you.
please do remove #parent { display: flex;} and also remove #icons { width: 100% }
It looks in line to me (see below image) however the margins/padding make it look like it's below and to the right.
Other things which may prove useful having seen your code:
display: inline-table
http://flexboxgrid.com/
remembering to keep CSS files as small as possible, not as comprehensive as possible to make it easy to find and fix things
Your image of logo class not in center of its parent. Add
text-align: center;
margin: auto;
into you .logo class