If I correctly understand what you want, you may leave the width and height attributes off the image to maintain aspect ratio and use flexbox to do the centering for you.
.fill { display: flex; justify-content: center; align-items: center; overflow: hidden } .fill img { flex-shrink: 0; min-width: 100%; min-height: 100% }
<div class="fill"> <img src="https://picsum.photos/id/237/320/240" alt="" /> </div>
I tested this successfully in IE9, Chrome 31, and Opera 18. But no other browsers were tested. As always you must consider your particular support requirements.
Related Posts:
- How to vertically align an image inside a div
- Change color of PNG image via CSS?
- How to fade an image with CSS without opacity?
- Define an ‘s src attribute in CSS [duplicate]
- How to place Text and an Image next to each other in HTML?
- Adding a blurred border in CSS
- Contain an image within a div?
- CSS force image resize and keep aspect ratio
- sizing div based on window width
- How do I center an SVG in a div?
- Removing whitespace between HTML elements when using line breaks
- How to get multiple images to auto resize and stay centered within a div
- Remove blue underline from link
- CSS Background Opacity [duplicate]
- “Stray start tag footer” in html validator?
- HTML Width Percentage
- draw diagonal lines in div background with CSS
- How to set up fixed width for
? - Play multiple CSS animations at the same time
- Why are my CSS3 media queries not working on mobile devices?
- CSS3 Transition – Fade out effect
- border-radius not working
- bootstrap 4 row height
- sass :first-child not working
- How to add image that is on my computer to a site in css or html?
- Twitter Bootstrap – add top space between rows
- Hex colors: Numeric representation for “transparent”?
- HTML colspan in CSS
- Flexbox float right
- Text wrapping around a div
- Iframe’s overflow problem
- Show / hide div on click with CSS
- CSS to select/style first word
- img-responsive in Bootstrap does not work
- Hexagon shape with CSS3
- CSS selector for first element with class
- Inbuilt style for jquery-ui-datepicker
- Why is style.css not being enqueued?
- How to add a class to ul tags created by the WordPress editor Tinymce?
- Using theme options to change link colours
- How make theme css be first and not plugin css
- When enqueing a stylesheet, is it possible to remove the type attribute? [duplicate]
- One WordPress and database but multiple subdomains
- Collapsible button inside a ul list does work in jsfiddle but not in WP
- wordpress in wamp lan doesn’t load css
- JavaScript added as link/stylesheet
- Is there a default style.css
- How to get a value for admin css color either gray or blue
- CSS style button For WP Login Function in page template
- Adding external stylesheet after ALL other styles
- How can I use PurifyCSS to clean WordPress style.css?
- WordPress Twenty Fourteen Theme Sidebar
- Auto LTR-RTL Text Direction in wordpress post!
- Is there any size difference between single quote ‘ ‘ and double quote ” ” in CSS
- Removing Title From Links to Site
- Admin pages missing css
- WordPress problematic caching
- why this media query is not working / not loading when I put it in child theme?
- Rendering css to screen and debug problem
- How to link theme fonts directory in WordPress CSS?
- WordPress custom styles in menu page
- How to Style Primary Menu with Active Class
- Set 3 iframes in a row
- Unable to align my sidebar to the contents section instead of comments
- Google yolo one tab signup plugin avilable in wordpress? [closed]
- Get post format and use it as a CSS class in different spans
- wp_enqueue_scripts and CSS
- Using post_class to style posts indivdually
- Hiding Label via CSS
- Load custom CSS before admin CSS
- Custom CSS is not working?
- How can I style an IFRAME element that has a constantly changing class name? [closed]
- Twenty Twelve Calender Widget post titles creating disturbance
- Combine CSS Files without plugin
- My site on mobile version is not giving responsive view
- Missing “Additional CSS” option in Customizer
- Adding a new block editor color option to a theme
- check the first login for specific roles
- Trying to make an image a circle in Gutenberg
- How to style a list item when the radio input button within that li is :checked
- Custom CSS based on the Author of a Post
- adding additional class to get the post thumbnail [duplicate]
- Web Developer Console: “Slow network is detected.” with fonts
- I can not change the background-color value of wp: meta_value of content.xml
- Problem alignment issue with echo knowledge base
- Complex List Field – Gravity Forms
- issues with a slider – investigations with firebug
- My custom theme text and content format
- CSS Changes made, lost mobile functionality
- Display different css or Information based on previous page
- Color Picker – Theme options
- How to edit wordpress native gallery’s css file?
- Animate.CSS with a child theme
- why css doesnt work when i change my file of wordpress and sql to another computer?
- Change Twenty twelve theme background color
- remove author and date from all posts [closed]
- Add woocommerce plugin in own theme
- Hiding fields a form in via CSS [closed]
- Can physically see CSS changes occur when refreshing page
- How to remove class=”wp-block-heading” from Heading tags?