
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
How an
or
Use the object-fit property in CSS to resize image or video to fit its container.
Example
You can try to run the following code to achieve this.
<!DOCTYPE html> <html> <head> <style> .myimg { width:250px; height:350px; object-fit:fill; } </style> </head> <body> <h2>SWIFT</h2> <img class = "myimg" src = "https://www.tutorialspoint.com/assets/videos/courses/67/images/course_67_image.png" alt = "Python Data Science" width = "300" height = "200"> </body> </html>
- Related Articles
- How to auto-resize an image to fit a div container using CSS?
- How to Position Element to Bottom of Its Container with CSS Flex
- Set whether an animation should be played forwards or using CSS
- How to specify the number of columns an element should be divided into with CSS
- Set how many times an Animation should run with CSS
- How to set or return the number of columns an element should be divided into with JavaScript?
- Determine whether an element should be visible when not facing the screen with CSS
- Set how many columns an element should span across with CSS
- Which one is good to be fit Jogging, Gym or Yoga?
- Set whether the text should be overridden to support multiple languages with CSS
- How to align an item to the flex-end in the container using CSS ?
- How to Rotate Container Background Image using CSS?
- How to stretch elements to fit the whole height of the browser window with CSS?
- How to set div width to fit content using CSS?
- Specify whether the flex items should wrap or not with CSS

Advertisements