How to resize images on my presentation website depending on different screen resolutions? For example, on a resolution like 2560x1440 the width of the images is too big. I want it to go from 28% to 20% because that's how i think it will look better. But only for that screen resolution, in other screen resolutions like 1280x720 it's ok.
This is an image of what i'm saying, with the 28% width: https://imgur.com/OPUbdWz
And this is how i want to transform it, with 20% width on that specific screen resolution: https://imgur.com/iXLAe8l
This is my trying in CSS, but not working:
#media (max-width: 2000px){
.amenajari_interioare_css{
width: 20%;
}
}
And this is my HTML and CSS code:
HTML:
<section id="showcase">
<div class="container">
<h1>LOCUINČšE</h1>
<div class="amenajari_interioare_css">
<img src="../img/locuinta1.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta2.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta3.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta4.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta5.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta6.jpg" alt="" />
</div>
</section>
CSS:
.amenajari_interioare_css{
min-width: 350px;
width: 28%;
height: 300px;
display: inline-block;
margin: 8px;
position: relative;
}
.amenajari_interioare_css img{
margin-top: 5px;
margin-bottom: 1px;
width: 100%;
height: 100%;
border: 1px solid black;
border-radius: 16px;
}
You have a couple errors in your CSS - mainly the media query. It should be min-width, because you want the change to happen for screen sizes above 2000px.
#media (min-width: 2000px){
.amenajari_interioare_css {
width: 20%;
}
}
The other thing you should probably do is:
.amenajari_interioare_css img{
margin-top: 5px;
margin-bottom: 1px;
width: 100%;
height: auto;
border: 1px solid black;
border-radius: 16px;
}
Set the height to auto or in the event you don't have a perfectly square image, otherwise that image will get stretched.
Related
I'm trying to align two images side by side - pair after pair down by landing page on wide screen and single image - one after another on mobile screen layout:
<div class="container">
<div class="set">
<div class="column">
<img src="" id="img3" class="images">
</div>
<div class="column">
<img src="" id="img4" class="images">
</div>
<div class="column">
<img src="" id="img5" class="images">
</div>
<div class="column">
<img src="" id="img6" class="images">
</div>
</div>
</div>
container css:
.container {
height: relative;
padding: 0px 12px;
margin-top:0px;
margin-bottom:0px;
border-radius: 0px;
background-color: transparent;
}
set and column css:
* {
box-sizing: border-box;
}
.set {
display: flex;
}
.column {
flex: 33.33%;
padding: 5px;
}
images css:
.images {
position: relative;
width: 100%;
height: auto;
padding: 23px;
}
Actual result is a scalable images in one line with both screen layouts, left is a wide screen, right is mobile:
but I'm trying to get this result:
You just need to give one more parameter in your css file
#media screen and (max-width:768px){
.set{display:block}
}
I've been trying to line up my images to the same size, using CSS and HTML tags, currently this is what I've come up with, there are just a few pictures that don't seem to follow the directions. I have tried different ways to describe the width (e.g: vw, hf, px or %), though those tags don't seem to completely sort the problem out here. The width is alright, yet the height on some pictures is not.
All pictures have different original sizes, only the last 3 pictures are exactly the same original size.
I have definitely tried finding the same issue asked elsewhere on the internet, but I haven't found anything related yet.
Any ideas on how to fix this, without having to manually edit all the pictures to the thumbnail size?
This is what the images currently look like.
code
.main-container {
max-width: 60%;
max-height: 44.44%;
margin-left: 19.6875%;
margin-top: 20%;
padding: 10px;
overflow: hidden;
background-color: #FEF39F;
}
.imgclass {
border: 1px solid #ddd;
border-radius: 4px;
padding: 5px;
max-width: 13.5vw;
max-height: 15hz;
}
img.imgclass:hover {
box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}
max-height and max-width will only specify that the image should not be more than the specified height and width respectively. Try something like img { height: 200px; width: 100%}
May be you wanna do this:
* {
box-sizing: border-box;
}
/* Create four equal columns that floats next to each other */
.column {
float: left;
width: 25%;
padding: 10px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
.column img{
height: 250px;
width: 100%;
}
#media screen and (max-width: 600px) {
.column {
width: 50%;
}
.column img {
height: 180px;
width: 100%;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>Four Equal Columns</h2>
<div class="row">
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
<div class="column">
<img src="https://picsum.photos/700/600" >
</div>
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
</div>
<div class="row">
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
<div class="column">
<img src="https://picsum.photos/400/600" >
</div>
<div class="column">
<img src="https://picsum.photos/500/600" >
</div>
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
</div>
</body>
</html>
How do I use multiple images which are different in resolutions.. But I want to use all in a perticular size without stretching and make everything responsive..
* {
margin: 0;
padding: 0;
border: none;
outline: none;
}
body {
width: 80%;
margin: 0 auto;
}
.imags img {
width: 45%;
margin: 1%;
}
<section class="imags">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/36/Hopetoun_falls.jpg" alt="wall">
<img src="https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb&h=350" alt="wall">
<img src="https://images.pexels.com/photos/236047/pexels-photo-236047.jpeg?auto=compress&cs=tinysrgb&h=350" alt="wall">
<img src="https://www.nature.com/polopoly_fs/7.44180.1495028629!/image/WEB_GettyImages-494098244.jpg_gen/derivatives/landscape_630/WEB_GettyImages-494098244.jpg" alt="wall">
<img src="https://assets.uuworld.org/sites/live-new.uuworld.org/files/styles/scaled_960_wide_no_upscale/public/istock-678573106-smaller.jpg?itok=sDKAwLhI×tamp=1523631303" alt="wall">
</section>
Consider this example...
You can use this code
HTML
<div class="block">
<img class="responsive-img" src="image1.jpg" alt="image"></img>
</div>
<div class="block">
<img class="responsive-img" src="image2.jpg" alt="image"></img>
</div>
CSS
.block {
width: 500px;
}
.responsive-img {
width: 100%;
height: auto;
}
//If the screen size is less than 480px, the image width will be the width of the screen
#media screen and (min-width: 480px) {
.block {width: 100%}
}
Here each images will adjust in 500px width and the height will varies as their height to width ratio.
Or you can use Bootstrap 4, a CSS framework which have predefined classes for the same.
<div class="col-*-*">
<img class="img-fluid" src="image1.jpg" alt="image"></img>
</div>
<div class="col-*-*">
<img class="img-fluid" src="image2.jpg" alt="image"></img>
</div>
Here img-fluid is the class to get the responsive image in Bootstrap 4. In Bootstrap 3, the class img-responsive
If you want to fix the height also, then
.block {
width: 500px;
height: 500px;
overflow: hidden;
}
.responsive-img {
min-width: 100%;
min-height: 100%;
}
The CSS code above will allow the images to adjust in 500px*500px box without stretching. In the result if the image width is greater than height, the height will be 500px and the width will be more than 500px, but the extra part will be hidden, vice-versa for if the height is greater than width.
Hope my answer meet to your query.
https://codepen.io/sawacrow/pen/zYWvzQR
aspect-ratio: 2/2;
object-fit: contain; or object-fit:cover;
I want to create the following layout :
Is a stripe of a variable number of images that have various widths and heights, that are:
proportional
scaled at the same height;
and the sum of their widths are equal to the parent width.
***It's kind of complicated to express myself;
I was wondering if it's possible for a block to simulate the img neat proportion behavior when you set a width to a percentage and it calculates the height of it automagically.
I've made up a diagram that maybe explain better what I want to achieve :
I want for the image to have collectively 100% width of the parent element, scaled with at the same height without loosing their proportion.
I've tried various implementations trying to figure out a way in which I can translate compute a percentage height in css that fills all the width for a block, just how the image behaves when there are {width: 100%; height : auto} properties.
So here is what I've got so far :
Strike #1, tried a simple solution
Problem: container height must be predefined.
.container {
width : 100%;
border: 1px solid black;
height: 50px; /* I would like to say here auto */
}
.image-wrapper {
white-space: nowrap;
height: 100%;
max-width: 100%;
border: 1px dashed gray;
}
.image {
height: 100%;
width: auto;
}
<div class="container">
<div class="image-wrapper">
<img class="image" src="http://placehold.it/100x200" />
<img class="image" src="http://placehold.it/300x200" />
<img class="image" src="http://placehold.it/800x400" />
<img class="image" src="http://placehold.it/10x80" />
<img class="image" src="http://placehold.it/800x400" />
</div>
</div>
Strike #2, display: table anyone ?
Problem: Don't even need to mention it, images are cropped the container size doesn't follow its parent size .
.container-wrapper {
width: 40px;
height: 50px;
}
.container {
width : 100%;
border: 1px solid black;
display: table;
height: 100%;
}
.image-wrapper {
display: table-row;
height: 100%;
border: 1px dashed gray;
}
.item {
display: table-cell;
border: 1px solid blue;
width: 100%;
height: auto;
}
.image {
height: 100%;
width: auto;
}
<div class="container-wrapper">
<div class="container">
<div class="image-wrapper">
<div class="item">
<img class="image" src="http://placehold.it/100x200" />
</div>
<div class="item">
<img class="image" src="http://placehold.it/300x200" />
</div>
<div class="item">
<img class="image" src="http://placehold.it/800x400" />
</div>
<div class="item">
<img class="image" src="http://placehold.it/10x80" />
</div>
<div class="item">
<img class="image" src="http://placehold.it/800x400" />
</div>
</div>
</div>
</div>
***I must say that I am looking for a HTML/CSS solution without the involvement of JavaScript code.
Do you have a clue on how can I approach this ?
So a trick I just came up with is to use the automagic scaling of an image to scale the containing filmstrip div, but hide it with opacity (in a real example, I'd use a transparent .png as well). This sets the height of the filmstrip relative to its width. If you want your filmstrip to be 5:4 or 16:9 or whatever, just change the proportions of the .magic image.
The container inside is then set to be absolutely positioned so it inherits the size of the .magic image.
The images themselves are set to take up the full height of the filmstrip, and are given different widths. The actual image is set with background-image which uses background-size: cover and background-position: center to fill the div.
.filmstrip {
width: 100%;
position: relative;
/* just to make it easier to see what's going on */
border: 1px solid red;
}
.magic {
width: 100%;
height: auto;
display: block;
/* we don't actually want to see this, we're just using it for it's ratio */
opacity: 0;
}
.contents {
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
}
.contents .image {
height: 100%;
background-size: cover;
background-position: center;
float: left;
margin-right: 2%;
/* just to make it easier to see what's going on */
border: 1px solid blue;
box-sizing: border-box;
}
.contents .wide {
width: 30%;
}
.contents .narrow {
width: 10%
}
<div class="filmstrip">
<img class="magic" src="http://placehold.it/400x100" />
<div class="contents">
<div class="wide image" style="background-image: url('http://placehold.it/300x100');"></div>
<div class="narrow image" style="background-image: url('http://placehold.it/300x100');"></div>
<div class="wide image" style="background-image: url('http://placehold.it/300x100');"></div>
</div>
</div>
Browser support should be: Chrome 3+, Firefox 3.6+, IE 9+, Opera 10+, Safari 4.1+ which is basically because of the use of background-cover.
Have a look at my stackoverflow 33117027 answer in which I made suggestions about creating a filmstrip. It has a reference to an eleborate Codepen example. You can easily strip/add what you need...
i have a site that has a grid of images in the center,when i see it on my 1920*1080 desktop the images are properly spaced and it works great, but when seeing it on lower resolution (or if the user resizes the window) the images move and ruin the layout of the site. I need a way to scale the images when the site is displayed in lower resolution computers or the window is smaller.
<div class="imagenes" style="padding: 2px 0px 20px;">
<div class="row imagenes" style="display: inline">
<div class="col-sm-3" style= "height: 320px; width: 480px; margin-left:165px; box-shadow: 10px 10px 5px #888888;">
<img src="images/inscrib1.jpg"/>
</div>
<div class="col-sm-3" style= "height: 320px; width: 480px; margin-left: 25px; margin-right: auto; box-shadow: 10px 10px 5px #888888;">
<img src="images/inscrib2.jpg"/>
</div>
<div class="col-sm-3" style= "height: 320px; width: 480px; margin-left: 25px; margin-right: 165px; box-shadow: 10px 10px 5px #888888;">
<img src="images/inscrib3.jpg"/>
</div>
</div>
can anyone help me?
As per the Bootstrap docs: http://getbootstrap.com/css/#images
add the "img-responsive" class to the images.
<img class="img-responsive" src="..." />
Use media queries :
#media screen and (max-width : **the_size_you_want**px) {
.col-sm-3 {
width: **idem**px;
height: **idem**px;
}
.col-sm-3 img {
max-width: 100%;
height: auto;
}
}