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!
Related
How can you force a col to expand to the full width on right which is inside a container
<div class="container">
<div class="row">
<div class="col-5">
Lorem ipsum
</div>
<div class="col-7 img-col">
<img class="img-fluid" src="https://placeimg.com/640/480/nature/sepia"/>
</div>
</div>
</div>
I've tried to use position absolute on the right col but isn't going to stretch to the left
https://jsbin.com/cikuragaba/edit?html,output
.container {
position: relative;
}
.img-col {
position: fixed;
right: 0px;
width: 100%;
top: 0;
}
.img-fluid {
width: 100%;
}
This will set it to the full width but if you explain what you're trying to do I think there will be a better way than this to achieve it.
I believe that the div is already at full width, but the image is not. Add this CSS:
.img-fluid {
width: 100%;
}
Use:
.img-col .img-fluid {
width: 100%
}
This will make your image within the img-col 100% width. .img-fluid only specifies the max-width. Being specific with .img-col first doesn't make ALL .img-fluid 100% width.
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.
Here is plunker example, the left (yellow) cell is the relevant one. It isn't bootstrap-specific but I've used its classes to make the image responsive.
<div class="container">
<div class="row">
<div class="col-xs-6" style="padding:30px; background:yellow">
<div class="wrapper">
<img class="center-block img-responsive" style="position: absolute" src="..."">
<img class="center-block img-responsive" style="visibility: hidden" src="...">
</div>
</div>
<div class="col-xs-6" style="padding:30px; background:lime">
<img class="center-block img-responsive" src="...">
</div>
</div>
</div>
And relevant css, borrowed from bootstrap
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
.img-responsive {
display: block;
max-width: 100%;
width:90%;
height: auto;
}
.img-responsive:hover {
min-width:110%;
}
.wrapper {
position: relative;
height: 100%;
}
The thing I'm trying to accomplish:
Fit the image into the container (bootstrap column with some padding here) proportionally (ok)
Make it a bit smaller while keeping it at center, container's size is unchanged (ok)
Make it bigger on hover while still keeping it at center, container's size is unchanged (fixed with transform: scale)
The second layered image (absolute-positioned) should fit the size and the position of the first (not ok)
I've made placeholder<img> hidden to keep the container's size, but <img> with position: absolute aligns to the left anyway.
How this can be solved? I will use JS on page but clearly I'm not eager to use it to pin that image to the placeholder programmatically.
Make it bigger on hover while still keeping it at center, container's size is unchanged
Use CSS3's transform attribute :
.img-responsive:hover {
transform: scale(1.1);
}
https://developer.mozilla.org/fr/docs/Web/CSS/transform
Make sure to prefix the transform property:
http://caniuse.com/#search=transform
Plunker version: http://plnkr.co/edit/HYJ9XJ8rAc3cgVI0uKFe?p=preview
The second layered image (absolute-positioned) should fit the size and the position of the first
Add left: 0 and right: 0 to your absolute positioned element.
I am trying to position a <div> absolutely using bottom=50% in an AngularJS/Ionic page as follows:
HTML:
<ion-view title="BoardLine">
<ion-nav-buttons side="left">
<button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>
<ion-content class="has-header">
<div id="imagecontainer">
<img id="boardimage" ng-src="{{mainResultImagePath}}" />
<div id="photocredits" class="rotateimagecredits">
Image courtesy: {{computed.prophotocredits}}</div>
</div>
....
CSS:
#imagecontainer {
position:absolute;
top:3%;
left:0;
right:62%;
bottom:50%;
}
#boardimage {
position:absolute;
left:10%;
max-width:85%;
bottom:0;
height:100%;
}
But just before div id="imagecontainer", Ionic generates a div class="scroll",like below, which has a height of 20px. And the top and bottom css for my imagecontainer refers to this height, but the div class="scroll" has a position:static. Therefore my imagecontainer absolute positioning should refer to the first parent that has a non-static position
which should be the <ion-content>
<ion-content class="scroll-content ionic-scroll has-header">
<div class="scroll" style="-webkit-transform: translate3d(0px, 0px, 0px) scale(1);">
<div id="imagecontainer">
<img id="boardimage" ng-src="./img/boards/SD360.jpg" src="./img/boards/SD360.jpg">
<div id="photocredits" class="rotateimagecredits ng-binding">Image courtesy: john carper</div>
</div>
I'm not really sure this answers a question, but a valuable information for people struggling with Ionic and absolute position would be that
position: absolute
Has to be used with elements outside of ion-content
So:
<ion-content>
</ion-content>
<div class="bottom">
</div>
.bottom {
position: absolute;
bottom: 0px;
width: 100%;
}
The footer component of ionic is fixed regarding the screen, I think you can try to implement an equivalent one. More info about the footer: http://ionicframework.com/docs/v1/components/#footer
The main css-properties of the element are:
.bar-footer {
bottom: 0;
height: 44px;
}
.bar {
display: flex;
user-select: none;
position: absolute;
right: 0;
left: 0;
z-index: 9;
width: 100%;
height: 44px;
}
Modify the above properties with your specific ones (eg. bottom: 50%;) and ensure display is set as absolute.
Considering your parent's positionning issues, you should try to put your piece of code outside <ion-content></ion-content>, inside <ion-view></ion-view>.
It's the only way I succesfully set a button positioned as absolute within ionic mobile framework.
EDIT: /!\ Be careful not to write anything out of <ion-view></ion-view>. My previous answer was creating trouble in the way ionic manages the different pages.
I'm trying to find out how to define the height for this .gallery element based on the size of the img element inside it.
<div class="row">
<div class="large-10 columns">
<div class="gallery portrait">
<div class="cover">
<img src="http://placekitten.com/800/1029">
</div>
<ul class="thumbs">
<li class="thumb"></li>
<li class="thumb"></li>
<li class="thumb"></li>
</ul>
</div>
</div>
</div>
I'm using percentage-based heights and widths in my CSS to set the height and width of the elements inside my gallery. However, I'm defining the height of the .gallery element in pixels so my percentage elements work.
.gallery {
height: 680px;
}
I'm trying to get the height of the .gallery to adjust its self when the browser window is resized and my image gets smaller.
I've got a demo of the problem I'm having over here: http://codepen.io/realph/pen/kKAmx
Any help is appreciated. Thanks in advance!
If I understand what your issue correctly, then simply remove the height: entries on your gallery and cover class. The gallery element should expand contract to fit the image (as long as the image has % width).
Example Fiddle
CSS:
.gallery {
background: orange;
width: 100%;
float: left;
//height: 680px;
}
.cover {
float: right;
width: 63.8554217%;
//height: 680px;
overflow: hidden;
}
.gallery img {
width: 50%;
}