How can I resize all photos to the same size? - html

I have this site:link
but i have the following problem:problem
What I want to do is:
1. the two images must have a width of 33.3333% , but the middle image must
remain as it is
another of my problems is when I resize the browser,the middle image is much higher.
CSS
.inline-block{
display: inline-block;
vertical-align: top;
}
.left-img,.right-img{
width: 33.3333%;
}
.left-img{
background: url("/wp-content/themes/wp_bagel/assets/img/img-01.png");
background-size: cover;
}
.ctr-img{
background: url("/wp-content/themes/wp_bagel/assets/img/img-02.png");
background-size: cover;
}
.right-img{
background: url("/wp-content/themes/wp_bagel/assets/img/img-03.png");
background-size: cover;
}
HTML
<div class="left-img inline-block">
<img src="/wp-content/themes/wp_bagel/assets/img/img-01.png" alt="Mountain View" style="visibility: hidden;">
</div>
<div class="ctr-img inline-block">
<img src="/wp-content/themes/wp_bagel/assets/img/img-02.png" alt="Mountain View" style="visibility: hidden;">
</div>
<div class="right-img inline-block">
<img src="/wp-content/themes/wp_bagel/assets/img/img-03.png" alt="Mountain View" style="visibility: hidden;">
</div>

This will not be possible with just HTML / CSS. You will have to use Javascript. For your layout, I would suggest taking a look at Masonry.

What I understand from your question is that you're trying to make all the three images of the same size, and this isn't happening when you're resizing the browser.
Well that, I think, is because you're specifying the width of left and the right images as 33% of screen and you're not setting the width of middle image. Try adding the ctr-image class also to that CSS block. i.e.,
.left-img,.ctr-img,.right-img{
width: 33.3333%;
}
instead of just
.left-img,.right-img{
width: 33.3333%;
}

click here to website
https://www.sitepoint.com/web-foundations/resize-images-css/
you get an idea
use like that:
#media screen and (orientation: portrait) {
img.ri { max-width: 90%; }
}
#media screen and (orientation: landscape) {
img.ri { max-height: 90%; }
}

I suggest you to use framework with grid system (Bootstrap par exemple). With three images, you need to set .col-md-4, .col-sm-4, .col-xs-4 to each image and then you have a perfect display.
To make all three images have the same height, if u want, u can fix the height. If not, the following solution works well:
.image-container {
position: relative;
padding: 0 0 56.25% 0;
}
.image-container img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Change 56.25% to the value that is best for you and then you will have what you want.
This is an exemple with your images: Codepen

You have a { max-width: 100%; } in your main.css file, remove it, and add {width: 100%}...
img {
border: 0;
max-width: 100%; /* Remove this line */
width: 100%; /* Add this line */
height: auto;
}
Then, You must make all 3 images in same height! Resize your images to same height... for example if your minimum height is 177px (first image), the second image must resize to (184x177) and the last image must be (235x177).
Finally, add { width: 33%; } for the center image-div
.ctr-img {
width: 33%;
}

Related

image width to fit browser width

I would just like to know how to resize an image width to fit the browser width, The image is basically my header image that i want to fit the screen width.
I would thereafter need to place a div on the image. I have the following at the moment but nothing seems to work.
#container {
position: relative;
}
#divWithin {
position: relative;
top: 20%;
left: 20%;
padding: 5px;
background-color: white;
}
#imgWithin{
width: 100vw;
height: 100vh;
left: 0;
}
<div id="container">
<img id="imgWithin" src="~/images/image(2).png" style="height:325px; margin-top: 75px;" />
<div id="divWithin">Testing</div>
</div>
Any help or ideas would be gladly appreciated
What I am trying to achieve is displayed in an image below:
With 1 being : The image that I want displayed across the screen width (fit screen width)
and with 2 being : The div that I would want to place upon the image
To make a image responsive You need to use a class like this:
.responsive {
width: 100%;
height: auto;
}
If you need more details about responsive images this link should help https://www.w3schools.com/howto/howto_css_image_responsive.asp
Try changing your css to this:
html, body {
width: 100%;
}
#container {
width: 100%;
position: relative;
}
#imgWithin {
width: 100%;
}
#divWithin {
position: absolute;
top: 20%;
left: 20%;
padding: 5px;
background-color: white;
}
This will make the image the full width of the browser window with the text overlaid on top.
You are going to warp the image with a fixed height in your html though. If you provide a link to an image mocking up what you are trying to achieve I might be able to help you further
Why don't you use background: url()?
so new html now is:
<div id="container">
<div id="divWithin">Testing</div>
</div>
and css:
#container {
background: url("Your image url") no-repeat center center;
background-size: cover;
}
learn more about background and background-size
what ever media query you use put every where
CSS:-
.container{
padding: unset;
width:auto;
}
i am expecting inside container id is your image this works perfectly fine in every screen if you face any problem ping me

Image with max-width, and set height

I have a lightbox of photos and each photo is assigned a height of 85% of the viewport. When the window width is too small, the image is cut off, so they have a max-width of 100%;
.modal-image {
height: 85vh;
max-width: 90%;
}
However, when the max-width kicks in, the image is distorted because the height remains 85vh while the width changes with the screen width.
How could I keep the images at height 85vh except for when the max-width kicks in, at which point the height should be dynamic.
Thanks for the help
You might have a chance using a container for your image, so you could set the max-width in the container and the height on the image like so:
div {
max-width: 90%;
}
img {
height: 85vh;
object-fit: contain;
}
<div> <img src="https://pixar-community-production.s3-us-west-1.amazonaws.com/News/Effects_MTL_2018/rfm_rewrite.jpg" /> </div>
Using a container with a max-width allow us to have the right width, then using heighton the image allow the image to dynamically calculate its width without loosing its ratio.
You have to look in which screen resolution, the window "becomes" too small and create a css rule specific for every case. For example:
<style>
#media (max-width: 768px) {
.modal-image {
height: 85vh;
max-width: 90%;
}
}
#media (max-width: 1200px) {
.modal-image {
height: 85vh;
max-width: 90%;
}
}
</style>
Greetings!
Update: found an alternative solution
simply gave the image a container of width 85vh and height 85vh, and used object-fit: fill; so that the images scale properly.
<div class="container">
<img src="https://www.aussiespecialist.com/content/asp/en/sales-resources/image-and-video-galleries/jcr:content/mainParsys/hero/image.adapt.1663.medium.jpg" class="modal-image">
</div>
<style>
.container {
width: 100%;
height: 100vh;
padding: 100px;
object-fit: contain;
}
.modal-image {
width: 100%;
height: 100%;
}
</style>

Image to Fit Containing Div

I have done this many times before but it doesn't seem to work now for whatever reason. I want the image to be the full the width of the container but it doesn't. Any ideas?
jsFiddle: http://jsfiddle.net/Lqffk1ak/
Code:
img {
max-width: 100%;
max-height: 100%;
}
div {
background: #ccc;
}
<div>
<img src="https://s11.postimg.org/dpgqru2pv/Police2_600x250.jpg" class="full-width">
</div>
Just add width:100% to img
img {
width:100%
}
Looking at your class, what you should add is some CSS on the full-width class to make the img width 100%.
This way, only the images set as "full-width" will be forced 100%. The other one will keep the max-width rule of 100%, but won't be resized if they are smaller.
img {
max-width: 100%;
max-height: 100%;
}
.full-width {
width: 100%;
}
div {
background: #ccc;
}
<div>
<img src="https://s11.postimg.org/dpgqru2pv/Police2_600x250.jpg" class="full-width">
</div>
Just make your image width 100%. Even you resize your container image will fit on it.
img{
width:100%;
}
You can check the updated fiddle here
Change the css :
div {
height: 100%;
}
img {
width: 100%;
min-height: 100%;
}
I know this isn't directly an answer to your question but generally speaking, upscaled images look quite nasty. A way people get past this is to have the image centered and then add a blurred version behind it.
Like this:
body {
margin: 0;
}
.image {
position: relative;
text-align: center;
overflow: hidden;
font-size: 0px;
}
.background-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('https://s11.postimg.org/dpgqru2pv/Police2_600x250.jpg');
background-size: cover;
z-index: -1;
}
.blur {
filter: blur(10px);
}
<div class="image">
<div class="background-image blur"></div>
<img src="https://s11.postimg.org/dpgqru2pv/Police2_600x250.jpg" class="full-width">
</div>
I hope you find this helpful.
Because your Image is has 600px; height, and the you have set max-width:100%. So max-width property will only work when the parent dive will be smaller then 600px;.
To make image to the containing div, you have to give set image's property 100%; that is .full-width {width: 100%;}

Twitter Bootstrap carousel image appears distorted

I'm building a web site based on a theme built with Twitter Bootstrap: http://demo.graphikaria.com/agilis/theme.
Whenever I decrease the width of my browser the background image for the home page carousel becomes distorted.
For the default faded background image the template uses, this isn't a big deal, but if you want to use a clear image or logo instead it will appear distorted or squished.
If you use an IMG tag, it will always end up no wider than its container DIV. Because bootstrap re-sizes fixed images for fluid layout, especially on mobile, the images are squished to the screen width.
An alternative that seems to work well so far for me is to use a <div> tag with a background image.
The class:
.carousel-inner > .item > .carousel-image {
width: 100%;
height: 500px;
text-align: center;
align: center;
}
The Item Code:
#csl-item1 {
background:url(img/carousel_image1.jpg);
background-repeat: no-repeat;
background-position: center top;
}
The Item:
<div class="item active">
<div id="csl-item1" class="carousel-image"> </div>
<div class="container">
<div class="carousel-caption">
<!-- Caption -->
</div>
</div>
</div>
I'd be curious to see if anyone has any bugs with this method tho, so let me know if you think its a bad idea...
The cleanest solution I've found is adding this css to your image in the slide:
object-fit: cover;
overflow: hidden;
You can even just add it inline to the img tag:
<img style="object-fit: cover; overflow: hidden;" class="first-slide" src="/images/beach.jpg" alt="sunny day at the beach">
There's a great write-up that shows examples of CSS3 properties and their impact on image aspect ratios here: http://www.creativebloq.com/css3/control-image-aspect-ratios-css3-2122968
You have:
.carousel .item>img {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: 500px;
}
Change the height to 100%.
Looking at it in Chrome, the default max-width: 100% seems to not be what you want.
In your CSS, you can add to the already defined rules to get the browser to use the default.
.carousel .item > img { max-width: none }
It's worth noting that you specify min-width: 100% combined with an absolute height, so on large screens (like mine, which is 1080p), it will still distort the image if it gets too wide, thus changing the aspect ratio and again distorting the image.
OK, the best I could do was this…
/* Carousel base class */
.carousel {
height: auto;
margin-bottom: 60px;
}
/* Since positioning the image, we need to help out the caption */
.carousel-caption {
z-index: 35;
}
/* Declare heights because of positioning of img element */
.carousel .item {
background:#e64c6c;
border:.5px solid #e7c1af;
overflow:hidden;
padding:3px;
min-height: 500px;
}
.carousel-inner > .item > img {
float:right;
padding: 2px;
padding-left: 3px;
min-width: 500px;
}
.carousel-inner > .item > img:hover {
border: 1px solid #e7c1af;
}
With bootstrap 3.3.7, I could fix this issue by simply removing the 'height' line in carousel.css here:
.carousel-inner > .item > img {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
/*height: 500px;*/
}
In my case the image was distorted when the screen size increased. I was working off one of the start Bootstrap free templates (https://startbootstrap.com/) using Bootstrap 4.
Based on the answer above from Ira Herman (and I would comment if I had enough credit points), I ended up with the code below to solve my problem:
.carousel-item {
height: 32rem;
background-color: #777;
}
.carousel-item > img {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
height: 32rem;
object-fit: cover;
overflow: hidden;
object-position: 20% 19%;
}
The object-position x and y coordinates can be tweaked depending how you want the image to increase, decrease. Adjusting the image from the right also helped in my case. I hope that helps.

background-size contain, but don't scale up

I set my background image to contain:
.el {
background: url(path/to/img.jpg) no-repeat center center;
background-size: contain;
}
But that scales the image up. I want the image to never be bigger than its native dimensions, and only scale down when it won't fit at its native resolution.
Here's a demo: http://jsfiddle.net/6W3yh/
I'm looking for a solution in CSS only.
No JavaScript please.
Unfortunately, what you want to do isn't possible in CSS.
Your best bet is to set the background-size using Javascript.
However, if you want the image to scale down if the container is smaller than it, you will have to be able to retrieve the image's natural height.
if ($('.el').height() < imageHeight) {
$('.el').css('background-size', 'contain');
}
else {
$('.el').css('background-size', 'auto');
}
You could use Uncle Dave's Ol' Padded Box Technique for this. Here's a fiddle showing it in action.
div {
background: url(http://cdn4.iconfinder.com/data/icons/silent_night_icons/128/santa.png) no-repeat center center;
background-size: 100%;
width: 100%;
max-width: 128px;
height: 0;
padding-bottom: 100%; /* (Image Height / Image Width) * 100%; */
}
The only problem is that you'll need to know the width of your image for this to work. If you're using a CSS preprocessor like Compass you could offload this work onto the processor instead of doing it manually. Look here for information on that.
You may use this JQuery fix:
$('.target').each(function() {
if ($(this).css('background-size') == 'contain') {
var img = new Image;
var currObj = $(this);
img.src = currObj.css('background-image').replace(/url\(|\)$/ig, "").replace(/"/g, "").replace(/'/g, "");
img.onload = function(){
if (img.width < currObj.width() && img.height < currObj.height()) {
currObj.css('background-size', 'auto auto');
}
}
}
});
To get the natural width / height, you could put the background image in the html and hide it, then grab the image width / height with script.
HTML:
<div></div>
<img id="background" style="display: none" src="http://cdn4.iconfinder.com/data/icons/silent_night_icons/128/santa.png" />
JS:
var backgroundSize = $('#background').css('width');
I use two approaches:
1 - Object-Fit
This has good browser support: https://caniuse.com/#feat=object-fit
.container {
position: relative;
width: 200px;
height: 200px;
/* Just for style */
display: inline-block;
background: rgba(0,0,0,0.2);
margin: 10px;
}
.container img {
width: 100%;
height: 100%;
object-fit: scale-down;
}
<div class="container">
<img src="https://picsum.photos/300/200">
</div>
<div class="container">
<img src="https://picsum.photos/200/300">
</div>
<div class="container">
<img src="https://picsum.photos/100/100">
</div>
2 - Position and Transform
When you need to target older browsers, this works equally well with no change to your markup
.container {
position: relative;
width: 200px;
height: 200px;
/* Just for style */
display: inline-block;
background: rgba(0,0,0,0.2);
margin: 10px;
}
.container img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 100%;
max-height: 100%;
}
<div class="container">
<img src="https://picsum.photos/300/200">
</div>
<div class="container">
<img src="https://picsum.photos/200/300">
</div>
<div class="container">
<img src="https://picsum.photos/100/100">
</div>
CSS Solution: You need to know the height and width of the image.
#media screen and (max-width: 640px) and (max-height: 480px) {
div {
background-size: contain !important;
}
}
div {
background: #000 url('https://i.imgur.com/someimage.jpg') no-repeat center center;
background-size: 640px 480px;
}
Where the image url is https://i.imgur.com/someimage.jpg and the width and height of the image is 640px and 480px respectively.