3 Horizontal Box - CSS - html

What i would like to achieve is that i want to change the way my boxes appear only on the mobile version of the website. I experimented with display: and flex: rules but had no luck. I want them stick to each other but Couldn't find the right CSS rule. Help.
Thanks.
Example picture of how i want them:
The way they appear on desktop version of the website:
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img /></div>

.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
#media only screen and (max-width: 1000px) {
.main {
display: flex;
gap: 10px;
}
.m-image {
border: solid black 3px;
}
}
<div class = "main">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" />
</div>
</div>
Couple of things to think about when it comes to mobile view. When wanting certain items to display a certain way on mobile view you want to use #media only screen and (max-width: /* width of the device */. Place all the CSS rules inside of here. These rules will change the rules set above or run new rules that you have define below.
Also, when it comes to display: flex; you want to make sure you wrap it into another div. This "wrapper" or "container" will provide the structure to the way you want the images to display.

add a main container to compress the class m-image then add display flex
Ex:
<div id="main-container">
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
.main-container {
display: flex;
}
then add padding left and right to your m-image class

what you should do in this case is put your images in a single container and apply flex property in the css.
basically manipulate your html and css like this.
HTML:
<div class="image-container">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img />
</div>
</div>
CSS:
.image-container{
display:flex;
gap: 8px;
flex-wrap: nowrap;
}
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
This should give you your desired result for the desktop and for the mobile version you will have to apply media query into your CSS code.
hope this answers your question!

I couldn't really understand your code, So I wrote one for you suiting your needs
I hope it will fix your problem!
#content{
display: flex;
justify-content: space-around;
width: 100%;
}
.imagecontainer{
overflow: hidden;
width: 30%;
}
img{
width: 100%;
}
<div id="content">
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg"></div>
</div>

Related

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 fit images of any size to parent div

I've got an image slider, the selected image is set as the main image above. All the images are not same size. How do I make sure that each image is centered in the parent div and the entire parent div?
I'm now doing it with:
width: 100%;height: 100%;object-fit:fill;
but then my image loses the bottom of its content. I would like to center the image vertically.
My parent div has following class style:
.wrapper_image{
max-width:100%;
max-height:100%;
min-height:100%;
min-width: 100%;
margin: 0 auto;
}
code:
<div class="o-grid__col u-12/12" style="width: 400px;
height: 400px;
position: relative;
display: inline-block;
overflow: hidden;
text-align: center;
margin: 0;">
<div class="mySlides wrapper_image_horses">
<img src='url' style="width: 100%;height: 100%;object-fit:fill;">
</div>
</div>
I suggest you use display: flex; to achieve this. With flex it is much easier for you to align you images to center vertically and horizontally. Below is a test code I have done. Hope it helps with your problem
HTML
<div class="d-flex h-100">
<div class="img-slide">
<img src="https://via.placeholder.com/150">
</div>
</div>
CSS
.d-flex {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.h-100 {
height: -webkit-fill-available;
}
JS Fiddle Link : https://jsfiddle.net/SJ_KIllshot/y5fzvox8/
Here is a modern solution, hope it will help you
DEMO
<div class="o-grid__col u-12/12" style="width: 400px;
height: 400px;
position: relative;
display: inline-block;
overflow: hidden;
text-align: center;
margin: 0;
border: 1px solid #000;">
<div class="mySlides wrapper_image_horses" style="position: absolute;
top: 50%; left: 50%;
transform: translate(-50%,-50%);">
<img src='https://picsum.photos/id/159/200/200' style="width: auto;height: auto;">
</div>

Overlapped, multiple images in a responsive container

I have a responsive container and one image within it. It works good. The container and the image are resizing when the window-size changes. But, I need not only one, but more images which exactly overlap each other (all of them have the same size). How can I achieve this with HTML and CSS?
.pageCenter {
display: block;
max-width: 980px;
margin: 0 auto;
width: auto;
float: none;
border: 5px solid red;
}
.imageContainer img {
display: block;
margin: 0 auto;
width: auto;
}
img {
position: relative;
}
<div class="pageCenter">
<div class="imageContainer">
<img src="https://placeimg.com/400/200/nature" style="width:100%;" />
</div>
</div>
You could use grid in order to specify what row and column you want all images to sit in. They will then overlap and adjust to your container (do note the images I am using are all the same picture, but if you inspect, the 3 images are on-top of eachother:
.pageCenter {
display: block;
max-width: 980px;
margin: 0 auto;
width: auto;
float: none;
border: 5px solid red;
}
.imageContainer{
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr;
margin: 0 auto;
width: auto;
}
img {
position: relative;
grid-row: 1;
grid-column: 1;
}
<div class="pageCenter">
<div class="imageContainer">
<img src="http://www.fillmurray.com/800/400" style="width:100%;" />
<img src="http://www.fillmurray.com/800/400" style="width:100%;" />
<img src="http://www.fillmurray.com/800/400" style="width:100%;" />
</div>
</div>
Also note that grid isn't supported by all old browser
.imageContainer {
position:relative;
}
.imageContainer .img-1 {
position:absolute;
top:0;
left:0;
}
.imageContainer .img-2 {
float:left;
}
.clearfix {
clear:both;
}
<div class="pageCenter">
<div class="imageContainer">
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-1" />
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-1" />
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-1" />
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-2" />
<div class="clearfix"></div>
</div>
</div>
You need to set the parent to position:relative; and the images (.child) to position:absolute;
Updated with images, they overlap.
Updated again with your code.
Update #3: You need to set one image to position:absolute and one to float and add a clearfix element.

CSS position float

I try to display a left and right area but it's not working actually with the cotes "right" and "left"
I tried the position :absolute but it's display me something strange
Maybe I'm doing something wrong with my conteneur div or my div element1
Someone knows how I can achieve that?
#conteneur {
padding-top: -25px;
display: flex;
border: 2px solid black;
padding-bottom: 10px;
}
#element1 {
display: block;
width: 350px;
border: 1px solid black;
}
.right {
float: left;
width: 100%;
}
.left {
float: right;
width: 100%;
}
<div id="conteneur">
<div id="element1">
<img src="{{ public_path('../public/uploads/logo-FFRXIII-2017-01.png')}}" style="max-width: 300px;">
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
</div>
</div>
you are using flexbox, so stick with flexbox and forget floats
#conteneur {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
border: 1px solid black;
padding-bottom: 10px;
}
.img {
flex: 0 100%;
}
img {
max-width: 300px;
}
<div id="conteneur">
<div class="img">
<img src="http://placehold.it/300x200">
</div>
<div class="right">
adresse_right
</div>
<div class="left">
adresse_left
</div>
</div>
First of all your
<div id="right">
adresse_right
</div>
<div id="left">
adresse_left
</div>
Won't react to your CSS since these are ID's and in your CSS you are trying to find classes with the . selector. So change the . to a # or change your ID tags to Classes.
Secondly i've created a jsfiddle and edited your code hope this helps!

HTML images not aligned when they are not the same image

I'm making an image view thing, and am having some trouble with aligning the images. When I have two of the same image in a row, it will be aligned, but when the images are different, the second image will go lower than the first. Here is screenshot screenshot. Here is my html and css
html
<div id="wrapper">
<div id="images">
<div class="image" onClick="showimage('users/images/username/battlefield4_maars.png','battlefield4_maars.png','3.91MB','png');">
<img src="users/images/username/battlefield4_maars.png">
<div class="normaltext">battlefield4_maars.png</div>
</div>
<div class="image" onClick="showimage('users/images/username/dark_souls_2.jpg','dark_souls_2.jpg','363KB','jpg');">
<img src="users/images/username/dark_souls_2.jpg">
<div class="normaltext">dark_souls_2.jpg</div>
</div>
<div class="image" onClick="showimage('users/images/username/thief.jpg','thief.jpg','393KB','jpg');">
<img src="users/images/username/thief.jpg">
<div class="normaltext">thief.jpg</div>
</div>
</div>
</div>
css
#images {
margin-top: 20px;
display: inline-block;
}
.image {
height: 200px;
width: 140px;
border: 1px solid #cccccc;
border-radius: 3px;
background: #fff;
display: inline-block;
word-wrap:break-word;
padding: 10px;
cursor: pointer;
}
.image img {
width: 140px;
height: 140px;
}
Anyone know what's wrong here?
add this:
#images {display:block;}
.image {
vertical-align: top;
}