how to resize image thumbnails without stretching - wordpress

I currently have a blog page in Wordpress where my original images are all different sizes. I am having trouble getting the image thumbnails on my blog home page to all be the same width and height without stretching the image and also being able to remain responsive when resizing the screen.
Current blog page can be seen at http://studio10interiordesign.com/blog-2/
Current html:
<article class="slide-entry flex_column post-entry post-entry-3536 slide-entry-overview slide-loop-2 slide-parity-even av_one_third real-thumbnail" itemscope="itemscope" itemtype="https://schema.org/BlogPosting" itemprop="blogPost">
<img width="495" height="400" src="http://studio10interiordesign.com/wp-content/uploads/2018/03/1260-S-Bellaire-Denver-CO-print-002-1-Clubhouse-2700x1800-300dpi-495x400.jpg" class="attachment-portfolio size-portfolio wp-post-image" alt="" srcset="http://studio10interiordesign.com/wp-content/uploads/2018/03/1260-S-Bellaire-Denver-CO-print-002-1-Clubhouse-2700x1800-300dpi-495x400.jpg 495w, http://studio10interiordesign.com/wp-content/uploads/2018/03/1260-S-Bellaire-Denver-CO-print-002-1-Clubhouse-2700x1800-300dpi-845x684.jpg 845w" sizes="(max-width: 495px) 100vw, 495px"><span class="image-overlay overlay-type-extern" style="left: -5px; top: 0px; overflow: hidden; display: block; height: 261px; width: 333px;"><span class="image-overlay-inside"></span></span>
<div class="slide-content">
<header class="entry-content-header">
<h3 class="slide-entry-title entry-title" itemprop="headline">My Hygge</h3>
<span class="blog-categories minor-meta">
Uncategorized
</span>
<span class="av-vertical-delimiter"></span>
</header>
<div class="slide-entry-excerpt entry-content" itemprop="text"></div>
</div>
</article>
<article class="slide-entry flex_column post-entry post-entry-3436 slide-entry-overview slide-loop-3 slide-parity-odd post-entry-last av_one_third real-thumbnail" itemscope="itemscope" itemtype="https://schema.org/BlogPosting" itemprop="blogPost">
<img width="495" height="330" src="http://studio10interiordesign.com/wp-content/uploads/2017/03/Historic-Remodel-1home-image_Large-1.jpg" class="attachment-portfolio size-portfolio wp-post-image" alt="" srcset="http://studio10interiordesign.com/wp-content/uploads/2017/03/Historic-Remodel-1home-image_Large-1.jpg 2048w, http://studio10interiordesign.com/wp-content/uploads/2017/03/Historic-Remodel-1home-image_Large-1-300x200.jpg 300w, http://studio10interiordesign.com/wp-content/uploads/2017/03/Historic-Remodel-1home-image_Large-1-768x512.jpg 768w, http://studio10interiordesign.com/wp-content/uploads/2017/03/Historic-Remodel-1home-image_Large-1-1024x683.jpg 1024w, http://studio10interiordesign.com/wp-content/uploads/2017/03/Historic-Remodel-1home-image_Large-1-700x466.jpg 700w" sizes="(max-width: 495px) 100vw, 495px"><span class="image-overlay overlay-type-extern"><span class="image-overlay-inside"></span></span>
<div class="slide-content">
<header class="entry-content-header">
<h3 class="slide-entry-title entry-title" itemprop="headline">Sui Generis: A person or thing that is unique, in a class by itself.</h3>
<span class="blog-categories minor-meta">
Uncategorized </span><span class="av-vertical-delimiter">
</span>
</header>
<div class="slide-entry-excerpt entry-content" itemprop="text"></div>
</div>
</article>
CSS
.avia-content-slider .slide-image, .avia-content-slider .slide-image img {
border-radius: 3px;
display: block;
position: relative;
-webkit-perspective: 1000px;
-webkit-backface-visibility: hidden;
margin: 0 auto;
vertical-align: middle;
}
I've thought about adding width: 100% and height: 255px or height: auto but defining a set pixel height seems to stretch some images and I don't want that, especially when resizing the screen. The auto property doesn't seem to give the same height to all images, so I can't use that either.
Any info is appreciated.

Dependens on your css file, you have a two ways to solve it:
Just add the width and height witch you want to give for image show size (fast, but no the good solution for responsive site);
Wrapp the image tag in the support div tag with given width and height for it in your category layout file of WP theme.
For first case, just add to your css file:
.avia-content-slider .slide-image, .avia-content-slider .slide-image img {
border-radius: 3px;
display: block;
position: relative;
-webkit-perspective: 1000px;
-webkit-backface-visibility: hidden;
margin: 0 auto;
width: 100%;
height: 200px;
}
For second solution try:
<div style=" width: 100%; height: 200px; ">
<img width="495" height="400" src="http://studio10interiordesign.com/wp-
content/uploads/2018/03/image006-495x400.png" class="attachment-portfolio
size-portfolio wp-post-image" alt="">
</div>
with css for img tag:
.avia-content-slider .slide-image, .avia-content-slider .slide-image img {
border-radius: 3px;
display: block;
position: relative;
-webkit-perspective: 1000px;
-webkit-backface-visibility: hidden;
margin: 0 auto;
position: relative;
min-height: 100%;
min-width: 100%;
top: -50%;
}

Basically there is no way you can resize all images to the same size and at the same time, maintain their ratios and layouts. However, there is a couple of techniques to make the images look pretty fine and not pixelated.
Using the image as a background, if you have a container with fixed height and width, use the image as a background together with background-size: cover will make sure that the image will always be automatically resized to fit inside the container. background-position then can also be used to move the background image inside the container and display the most prominent part.
Using object-fit. This css property will cut off the sides of the image, preserving the aspect ratio, and also filling in the space. However, it is only supported in IE 16, so if you need to support older versions, it might be a problem.

Related

Make div height Responsive when page is resizing

I have a responsive slider with full-screen images. When I resize the page images stays responsive but the problem Im running into is that the parent div stays to the original height and I get very big white space and I dont know a method to fix the issue.
Sorry but i don`t know how to explain this,maybe youy can figure out from the image i added.
<!-- !Showcase -->
<div id="showcase">
<i id="arrow-left" class="arrow far fa-arrow-alt-circle-left "></i>
<div id="slider">
<div class="slide slide1"></div>
<div class="slide slide2 "></div>
<div class="slide slide3"></div>
</div>
<i id="arrow-right" class="far arrow fa-arrow-alt-circle-right "></i>
</div>
#showcase {
height: 500px;
width: 100%;
position: relative;
}
#slider {
height: inherit;
width: 100%;
overflow-x: hidden;
}
.slide {
width: 100%;
height: inherit;
background-size: contain !important;
}
.slide1 {
background: url(/Core/img/lazar1.jpg) no-repeat center 10%/cover;
}
.slide2 {
background: url(/Core/img/lazar2.jpg) no-repeat center 10%/cover;
}
.slide3 {
background: url(/Core/img/lazar3.jpg) no-repeat center 10%/cover;
}
Showcase has a fixed height, turn it into a min-height or remove it to allow the container to fit its content's
As G-Cyr said in his comment, your container element (#showcase) has an absolute height of 500px. That is what is blocking your element from filling up whenever your content would regularly go above 500px. If you want your baseline height of this container to be at least 500px, change height: 500px to min-height: 500px. That should work.

Align picture element in center of parent div keeps image aligned to left

I want to create a responsive hero image, but I can't seem to center my picture element in a parent div. I already checked these posts:
Center image in div horizontally
Center align image within div horizontally
Center image element in parent div
As suggested in these other posts, I tried playing with margin: auto auto;, with position, setting min-width to the parent div, but the image remains aligned to the far left.
Here's an example of what I'm trying to achieve
And here's my code (I've also created a jsfiddle: https://jsfiddle.net/wuy44t9p/1/):
<style type="text/css">
.profile-banner {
display: block;
height: 500px;
position: relative;
}
.profile-banner picture {
display: block;
margin: 0 auto;
position: absolute;
}
</style>
<div id="CPHBigBanner_pnlCoverPhoto">
<section class="profile-banner lazy">
<picture class="profile-herobanner lazy" data-was-processed="true">
<source type="image/webp" class="lazy" data-srcset="http://www.1001locaties.nl/images/tmp/41747_965_Owl.webp" srcset="/images/objphotos/covers/41747_965_Owl.webp" data-was-processed="true">
<img class="lazy loaded" data-src="http://www.1001locaties.nl/images/tmp/41747_965_Owl.png" alt="" src="/images/objphotos/covers/41747_965_Owl.png" data-was-processed="true">
</picture>
</section>
</div>
As per my comments you need to remove the absolute positioning from the image but also add text-align center to the container:
.profile-banner {
display: block;
height: 500px;
text-align:center;
}
.profile-banner picture {
display: block;
margin: 0 auto;
}
<div id="CPHBigBanner_pnlCoverPhoto">
<section class="profile-banner lazy">
<picture class="profile-herobanner lazy" data-was-processed="true">
<source type="image/webp" class="lazy" data-srcset="http://www.1001locaties.nl/images/tmp/41747_965_Owl.webp" srcset="https://via.placeholder.com/350x150" data-was-processed="true">
<img class="lazy loaded" data-src="http://www.1001locaties.nl/images/tmp/41747_965_Owl.png" alt="" srcset="https://via.placeholder.com/350x150" data-was-processed="true">
</picture>
</section>
</div>

Set image height to 75% of its container

I have a responsive image list. Each image is inside a container.
I want the image container to be 75% of its first container (unit container in this case)
the image ration is 1:1
I played a little with the image container percentage width but it feels like this is not the solution.
<ul class="list-inline unit_list ">
<li class="unit_list_item col-xs-24 col-sm-12 col-md-8">
<a href='#' alt="unit">
<div class="unit_container">
<div class="icon_container unit_icon">
<img class="img-responsive unit_image" src="http://placehold.it/60X60" />
</div>
<div class="unit_name">FREE</div>
</div>
</a>
</li></ul>
Btw, I'm using bootstrap if that's matter.
http://jsfiddle.net/wmu3w3ej/1/
Thanks to #Mary Melody
transform: scale(0.75);
works like magic
I'm a little afraid to use it since it's so simple.
any thoughts?
Using the logic from here: https://stackoverflow.com/a/20117454/3389737
I have applied it to your situation: http://jsfiddle.net/phwaLmen/1/
#wrapper
{
position: relative;
width: 50%;
overflow: hidden;
}
#wrapper:before
{
content: "";
display: block;
padding-top: 75%;
}
#image
{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
}
<div id="wrapper">
<img src="http://placehold.it/350x350" id="image">
</div>
Add relative positioning to the parent, set its width as you'd like and make sure the overflow is hidden.
Create a :before element for the wrapper with a padding-top of 75%. Since there is no height specified for the #wrapper, this 75% is based on the width of the element :)
Then you have your image, positioned absolutely and then fitted to the container. If you want the image to be cropped instead of resized, remove the height: 100% and width: 100% style rules from it.
You can do it like this (in your html):
<img src="img.jpg" height="75%" />
Good luck!

Safari gives padding on top and bottom of SVG logo

I made a logo in svg and implemented it on my website. It works well in all browsers EXCEPT safari
Here is a fiddle
NOTE - you muse use safari to recreate my issue. Viewing the fiddle in any other browser shows it like its suppose to be.
Here is my html for the navbar
<div class="navsection">
<div class="w-nav navbar" data-collapse="medium" data-animation="default" data-duration="400" data-contain="1">
<div class="w-container">
<a class="w-nav-brand" href="#">
<img class="logo" src="https://dl.dropboxusercontent.com/u/66131799/JA_logo_2014_svg.svg" width="100">
</a>
<nav class="w-nav-menu mobilenavmenu" role="navigation"><a class="w-nav-link navlinks" href="#work">work</a><a class="w-nav-link navlinks" href="#contact">contact</a>
</nav>
<div class="w-nav-button">
<div class="w-icon-nav-menu hamburger"></div>
</div>
</div>
</div>
</div>
What is causing this to happen?
You can get started with
preserveAspectRatio="xMinYMin meet" in your svg header
but I cant verify this without your svg on the fiddle
Your css
img {
display: block;
position: absolute;
width: 100%;
top: 0;
left: 0;
}
.w-nav-brand {
display: inline-block;
position: relative;
width: 50%;
padding-bottom: 60%;
}
The 60% needs tuning depending on size and width.
I've used this guide a lot, to good effect, but more with the object tag than img.
Try to trim the amount of css included in your fiddle, you'll get more interest!

Vertical aligning an absolute positioned div inside a containing div

I'm using the jQuery Cycle plugin to rotate images in a slideshow type fashion. That works fine. The problem I'm having is getting these images (of different sizes) to center in the containing div. The images are inside a slidshow div that has it's position set to absolute by the Cycle plugin.
I've tried setting line-height/vertical-align and whatnot but no dice. Here is the relevant HTML and CSS
HTML:
<div id="projects">
<div class="gallery">
<span class="span1">◄</span><span class="span2">►</span>
<div class="slideshow">
<img src="images/img1.png" />
<img src="images/img1.png" />
<img src="images/img1.png" />
</div>
</div>
</div>
CSS:
#main #home-column-2 #projects
{
width: 330px;
background: #fefff5;
height: 405px;
padding: 12px;
}
#main #home-column-2 #projects .gallery
{
width: 328px;
height: 363px;
position: relative;
background: url('images/bg-home-gallery.jpg');
}
#main #home-column-2 #projects .gallery img
{
position: relative;
z-index: 10;
}
And in case you want to see it, the jQuery:
$('#home-column-2 #projects .gallery .slideshow').cycle(
{
fx: 'scrollHorz',
timeout: 0,
next: "#home-column-2 #projects .gallery span.span2",
prev: "#home-column-2 #projects .gallery span.span1"
});
Any ideas on getting these images to center?
Try this:
http://www.brunildo.org/test/img_center.html
Vertical centering is a pain! Here's what the W3C page says about the vertical center:
CSS level 2 doesn't have a property
for centering things vertically. There
will probably be one in CSS level 3.
But even in CSS2 you can center blocks
vertically, by combining a few
properties. The trick is to specify
that the outer block is to be
formatted as a table cell, because the
contents of a table cell can be
centered vertically.
This method involves a little jquery, but works fantastic in most situations...
let me explain:
if all the images of the slideshow are contained within their own element div pos:absolute and those images are pos:relative, then on a $(window).load() you can run a .each() and find each img in the slideshow and adjust it's top positioning to be offset a certain number of pixels from the top..
jcycle automatically sets each parent div containing the image to pos:absolute on every onafter() so it's useless to apply this pos adjustment to them... instead target each img you have set to pos:relative...
Here is the example:
$(window).load(function() {
// move all slides to the middle of the slideshow stage
var slideshowHeight = 600; //this can dynamic or hard-coded
$('.slideImg').each(function(index) {
var thisHeight = $(this).innerHeight();
var vertAdj = ((slideshowHeight - thisHeight) / 2);
$(this).css('top', vertAdj);
});
});
and this is the html it's working on...
<div class="slideshow" style="position: relative; ">
<div style="position: absolute; top: 0px; left: 0px; display: none; width: 1000px; height: 600px; " id="img0">
<img class="slideImg" src="/images/picture-1.jpg" style="top: 0px; "><!-- the style=top:0 is a result of the jquery -->
</div>
<div style="position: absolute; top: 0px; left: 0px; display: none; width: 1000px; height: 600px; " id="img1">
<img class="slideImg" src="/images/picture-1.jpg" style="top: 89.5px; "><!-- the style=top:89.5px is a result of the jquery -->
</div>
<div style="position: absolute; top: 0px; left: 0px; display: none; width: 1000px; height: 600px; " id="img2">
<img class="slideImg" src="/images/picture-1.jpg" style="top: 13px; "><!-- the style=top:13px is a result of the jquery -->
</div>
</div>
just make sure
.slideImg {
position:relative;
}
I think that's everything... I have an example, but it's on a dev site.. so this link might not last.. but you can take a look at it here:
http://beta.gluemgmt.com/portfolio/rae-scarton-editorial.html
The positions are relative according to the style sheet, so did you try setting them to display: block and margin-top: auto; margin-bottom: auto; ?
Another option is to align them manually in javascript based on the containing div's height.
You need to nest two divs inside each cycle item. The first must have the display: inline-table; and the second must have display: table-cell; both these divs have vertical-align: middle.
So the structure would look something like this:
<div class="slide-container">
<div class="slide">
<div class="outer-container">
<div class="inner-container">
Centered content
</div>
</div>
</div>
<div class="slide">
<div class="outer-container">
<div class="inner-container">
Centered content
</div>
</div>
</div>
</div>
With the following css:
.slide-container {
height: 300px;
}
.outer-container {
height: 300px;
display: inline-table;
vertical-align: middle;
}
.inner-container{
vertical-align: middle;
display: table-cell;
}
You can see it working here http://jsfiddle.net/alsweeet/H9ZSf/6/

Resources