Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Tips] CSS Object-fit property

Thursday, 29 November 2018
|
Read: Completed in minutes

[Tips] CSS Object-fit property


The below code will help you process view of CSS in Image, using css object-fit property and calc function with 100vh

Always fix the image on view screen resolution
 .responsive-image {
        height: calc(100vh - 140px);        max-width: 100%;
        width: 100%;
    }

   <div class="modal-body" id="modal-body" style="width: 100%;">
    <div class="row">
        <div style="text-align: left;">
            <img class="image-control responsive-image " ng-src="{{srcImg}}" alt="Alternate Text" ng-style="myObj" />
        </div>
    </div>
</div>

- 100vh: full screen
- calc: calculator the number of screen resolution


Object-fit property

<style>
    .fill {object-fit: fill;}
    .contain {object-fit: contain;}
    .cover {object-fit: cover;}
    .scale-down {object-fit: scale-down;}
    .none {object-fit: none;}
</style>

The CSS object-fit property is used to specify how an <img> or <video> should be resized to fit its container.

This property tells the content to fill the container in a variety of ways; such as "preserve that aspect ratio" or "stretch up and take up as much space as possible".

Look at the following image from Paris, which is 400x300 pixels:

<h1>The object-fit Property</h1>

<h2>No object-fit:</h2>
<img src="paris.jpg" alt="Paris" style="width:200px;height:400px">

<h2>object-fit: fill (this is default):</h2>
<img class="fill" src="paris.jpg" alt="Paris" style="width:200px;height:400px">

<h2>object-fit: contain:</h2>
<img class="contain" src="paris.jpg" alt="Paris" style="width:200px;height:400px">

<h2>object-fit: cover:</h2>
<img class="cover" src="paris.jpg" alt="Paris" style="width:200px;height:400px">

<h2>object-fit: scale-down:</h2>
<img class="scale-down" src="paris.jpg" alt="Paris" style="width:200px;height:400px">

<h2>object-fit: none:</h2>
<img class="none" src="paris.jpg" alt="Paris" style="width:200px;height:400px">


Reference:
https://www.w3schools.com/css/tryit.asp?filename=trycss3_object-fit_all

CSS Object-fit property
CSS Object-fit property

CSS Object-fit property

CSS Object-fit property

CSS Object-fit property

CSS Object-fit property



Any feedback leave your comment, we can discuss about it!
Zidane



πŸ™‡πŸΌπŸ™‡πŸΌ Your Feedback Is Valuable and Helpful to Us - Webzone, all things Tech Tips web development Zidane
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com