I have setup a wordpress theme that uses featured images for header images on pages (I did this to make it easy for clients to modify on their own). Because the header image container needs to be a fixed size (100% width of the page and 300px heigh), I am using the "object-fit:cover" css callout which works perfect. The resulting effect is the image spans the full width of the page, and then is cropped vertically automatically (I did this so client would not need to manually size/crop the images before uploading them).
It works perfect with the exception of IE (of course). I have tried numerous possible workarounds from the "backgroundsize.htc" fix to javascripts, to absolute positioning and using the clip css feature, but it still does not give me the desired effect. IE insists on stretching the image. At this stage I am not sure if this is even doable in IE.
Here is my css for the featured image:
.wp-post-image {
width:100%;
height:300px;
position:relative;
display:block;
top:0px;
object-fit:cover;
}
img.wp-post-image {
max-height:300px;
margin:0 auto;
}
This code works in all browsers except IE, so I am using this code to feed IE overrides for the featured images:
#media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.wp-post-image {}
img.wp-post-image {}
}
Does anyone have advice for me as to how to force IE to "fill" the featured image container with its respective image and crop it instead of stretching it? Any help is really appreciated...
Put the image in a containing div with strategic use of overflow: hidden
.wrapper {
height: 100px;
overflow: hidden;
}
<div class="wrapper">
<img src="http://sd.keepcalm-o-matic.co.uk/i-w600/keep-calm-and-wrap-it-up-3.jpg" width=600 height=700>
</div>
Okay... figured it out. I hope this solution can help someone else in the future and a big THANK YOU to Anthony for his suggestion of the wrapper... something that I thought I had to avoid...
If you are wanting to implement a featured image in your Wordpress theme that automatically crops the media file a person uploads and not have IE screw it all up, do this:
For your regular featured image - add this implementation to your wordpress theme (I usually add it in the header.php file):
<div class="wrapper">
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
Then add this in your css:
.wp-post-image {
width:100%;
height:300px;
position:relative;
display:block;
top:0px;
object-fit:cover;
}
.wrapper {
height:300px;
overflow:hidden !important;
}
This will work with all browsers except IE (naturally). IE (even version 11) will skew the image within the featured image div. To fix that, add this code to the bottom of your css:
/*IE HACK*/
#media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
img.wp-post-image {
max-width: 100%;
height:auto;
width:auto;
top:50%;
left:50%;
transform: translate(-50%, -50%);
}
}
Adding the "max-width" and the "auto" for the regular height and width callouts, is what I was missing before.
Thanks to Anthony's suggestion to use a wrapper for the featured image, I was able to fill the wrapper with the image and force IE to not skew it. To make the image center (vertically and horizontally) in IE, I added the "top,left,transform" code which centres the large image within the wrapper in IE 11...
For anyone else using the twenty seventeen theme template, just chuck this into the "Additional CSS" section which is accessed by clicking "Customise" from your admin bar at the top of the screen. After a long time googling with limited coding knowledge, this has worked for me so figured I would share :) Special thanks to this thread for getting me in the right direction!
.single-featured-image-header img {
width:100%;
height:100%;
position:relative;
display:block;
top:0px;
object-fit:cover;
}
.single-featured-image-header {
height:25em;
overflow:hidden !important;
}
#media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
.single-featured-image-header img {
max-width: 100%;
height:auto;
width:100%;
}}
Related
I'm using a viewport device-width in my code. It works fine on cellphones for both text and pictures. The problem is, it zooms pictures too much on big screens so I tried to use media queries like this:
.img {
width:100%;
height:auto;
text-align:center;
}
#media screen only and (min-device-width:800px) {
.img {
width:1000px;
height:auto;
text-align:center;
}
}
Class .img is applied to the div containing <img>
With that, it works fine on big screens now, but it doesn't work on mobile anymore. The text is still fine but the image doesn't resize to the device width like before (and like in the meta viewport). I have no clue how to fix it.
If somebody has an idea,
Thanks,
Another option is to use max-width for an image. If an image is being stretched you would want to pick the largest size of the image as the max.
.img {
max-width: 500px;
}
That way the image will only stretch out so far.
Thanks for your answers guys. As i expected, the problem came from me. My "img" class was applied to the div containing the img.
The problem is, by this way, the width and max-width didn't work.
I just splitted the .img class into two class. the .divimg containing the text-align appy to the , and the .img containing width properties apply to the (not the like before).
Now it works fine. Thanks for help.
you can use id:
<html>
<head>
<title>Untitled</title>
<style>
#media screen and (max-width:600px){
#first{
width:100%;
}
}
</style>
</head>
<body>
<img src="" id="first" />
</body>
</html>
I have an instagram plugin installed, which i have put in the footer of my blog. on a desktop version, it is perfectly fine, however, on a mobile version, the screen is smaller and all the images align under each other, instead of 6 images next to each other as on desktop.
I would like to know, how can I make them 2 rows with 3 images on a mobile? where the 3 images together of each row take in 100% of the screen from left to right? with css?
I can't give you the full style css of the instagram plugin because it has a built-in css. But I can copy certain css element from the inspect element and put !important behind it. I just don't know how to do that.
you can see it here --> http://oihanevalbuenaredondo.be
EDIT
#media screen and (max-width:720px) {
#sb_instagram .sbi_col6 {
data-cols:3!important;
}
}
this is what i have now, it fixes that i got 3 images on each row, but the images arent square, and my images are cut, not resised
You would need to use a CSS #media query to target mobile, and add the following CSS:
#media (max-width: 640px) {
#sb_instagram.sbi_col_3 #sbi_images .sbi_item,
#sb_instagram.sbi_col_4 #sbi_images .sbi_item,
#sb_instagram.sbi_col_5 #sbi_images .sbi_item,
#sb_instagram.sbi_col_6 #sbi_images .sbi_item {
width: 33.33% !important;
}
#sb_instagram .sbi_photo img {
width: 100% !important;
display: inline-block !important;
}
#sb_instagram .sbi_photo {
height: 33vw !important;
overflow: hidden;
background: none !important;
}
}
Obviously you may or may not need to end up using !important for everything. Adding the above CSS results in the following:
Obviously I've swapped out your personal photos for placeholders, but the rest is your code.
http://www.bootply.com/tfGjhlJnPL
I'm trying to get the right-aligned navigation items to align vertically with the bottom of the left-aligned image.
I also want the navbar toggle button to line up with the bottom of the image in the same way when the navbar is collapsed...
Any suggestions welcome :)
Well, if you're not adverse to it, this can be achieved using primarily position:absolute. For example, based on the current styles you have, this CSS would work:
.navbar-header{
position:relative;
}
#media (max-width: 991px) {
.navbar-toggle{
position:absolute;
right:0;
bottom:0;
}
}
#media (min-width: 991px) {
.navbar-nav{
position:absolute;
right:0;
bottom:0;
}
}
Here's an updated Bootply to show you what this achieves. Depending on your preference, you may also want to adjust each element's padding or margin to alter just how close it is to the bottom of the header area (I did not change these styles in my demo). Hope this helps! Let me know if you have any questions.
I realise this question has been asked multiple times in differently worded titles and options, but i have yet to find something that works for me.
Im trying to have an img fill most of the screen (keeping its aspect ratio) without overflowing the edges. (Basically what the firefox browser accomplishes when viewing an image)
Most that i've tried either works in only one direction ie. width will resize but will end up overflowing the height and the same for the other way, either with CSS or JScript. Also playing a factor in my trouble is that i want to aplly this to both portrait and landscape images (More or less any image i have on the site)
This seems like it should work using pure CSS but doesnt (im not completely knowledgeable in all CSS though):
Link to JSFiddle
body, html {
margin:auto;
padding:6px;
height:100%;
width:100%;
}
img {
max-width:100%;
max-height:100%;
}
There are a hand full of other scripts as well, but this post is getting a bit long.
Could anyone help me out containing my images within the screen, with either JQuery or CSS (within or without a DIV)
Thanks in advance,
Try this jQuery plugin: TailorFit
and check out the demo.
You can play around with various options in the demo to figure out if this could work for you. The browser support is extreme because it only uses jQuery and relative positioning.
Full disclosure - I'm the author of the plugin.
Now define your html, body height 100%;
as like this
body, html {
height:100%;
}
MY ANSWER:
I ended up just wrapping the image in a div and setting the div dimensions in CSS:
PURE CSS Resize
Unfortunately this method may look quite horrible in older browsers but it has atleast got me out of a pickle and its a tiny piece of styling.
Hopefully i can find some jQuery alternative soon.
body, html {
width:98%;
height:98%;
}
.outer {
position:fixed !important;
position:absolute;
margin:auto;
text-align:center;
top:10px;
right:0;
bottom:10px;
left:0;
}
img {
max-width:100%;
max-height:100%;
padding:4px;
background-color:#fff;
}
----
<div class="outer">
<img src="whatever.jpg" />
</div>
I'm finding it tricky to resize images to make them responsive.
I'm developing a php application to automatically convert a website to a responsive version. I'm a little stuck on the images.
I've successfully added a wrapper class to every image on a website and can re-size the images quite well.
My issue lies with images that are naturally smaller than the the window, such as logos and icons. I don't want to resize these.
My code currently converts:
<img src="[src]" />
into:
<div class="erb-image-wrapper">
<img src="[src]" />
</div>
Where I use the following CSS:
.erb-image-wrapper{
max-width:90%;
height:auto;
position: relative;
display:block;
margin:0 auto;
}
.erb-image-wrapper img{
width:100% !important;
height:100% !important;
display:block;
}
This resizes all images, but I only want it to resize images that are over the width of the page. Is the a way I can achieve this via CSS?
.erb-image-wrapper img{
max-width:100% !important;
height:auto;
display:block;
}
Worked for me.
Thanks for MrMisterMan for his assistance.
Use max-width on the images too. Change:
.erb-image-wrapper img{
width:100% !important;
height:100% !important;
display:block;
}
to...
.erb-image-wrapper img{
max-width:100% !important;
max-height:100% !important;
display:block;
}
check the images first with php if it is small then the standerd size for logo
provide it any other css class and dont change its size
i think you have to take up scripting in between
um responsive is simple
first off create a class named cell give it the property of display:table-cell
then # max-width:700px do {display:block; width:100%; clear:both}
and that's it no absolute divs ever; divs needs to be 100% then max-width: - desired width - for inner framming. A true responsive sites has less than 9 lines of css anything passed that you are in a world of shit and over complicated things.
PS : reset.css style sheets are what makes css blinds there was a logical reason why they gave default styles in the first place.
the best way i found was to set the image you want to view responsively as a background image and sent a css property for the div as cover.
background-image : url('YOUR URL');
background-size : cover
Use max-width:100%;, height: auto; and display:block; as follow:
image {
max-width:100%;
height: auto;
display:block;
}