The Wayback Machine - https://web.archive.org/web/20240729211358/https://www.geeksforgeeks.org/how-to-use-flex-to-shrink-an-image-in-css/
Open In App

How to use flex to shrink an image in CSS ?

Last Updated : 30 Jul, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

You can easily shrink an image by using the flex-wrap property in CSS and it specifies whether flex items are forced into a single line or wrapped onto multiple lines. The flex-wrap property allows enabling the control direction in which lines are stacked. It is used to designate a single line or multi-line format to flex items inside the flex container. 

Syntax:

flex-wrap: wrap

Note: wrap is used to break the flex item into multiples lines. It makes flex items wrap to multiple lines according to flex item width.

Example: In order to shrink the image, you have to make the width of the image to 100%, so that image occupies 100% of the size of the <div>.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        .container {
            display: -webkit-flex;
            -webkit-flex-wrap: wrap;
            display: flex;
            flex-wrap: wrap;
            background-color: grey;
        }
  
        img {
            width: 100%;
        }
  
        div {
            flex: 1;
            padding: 10px;
            margin: 10px;
        }
    </style>
</head>
  
<body>
    <div class="container">
        <div class="image">
            <img src=
        </div>
        <div class="image">
            <img src=
        </div>
        <div class="image">
            <img src=
        </div>
    </div>
</body>
  
</html>


Output:

flex-wrap property



Similar Reads

Bulma Flex grow and flex shrink
Bulma is an Open source CSS framework developed by Jeremy Thomas. This framework is based on the CSS Flexbox property. It is highly responsive, minimizing the use of media queries for responsive behavior. In this article, we will learn about Bulma flex-grow and flex-shrink properties. The Bulma framework allows the users to use CSS flex-shrink and
2 min read
Tailwind CSS Flex Shrink
The CSS flexbox is a vital feature to develop the frontend, there is two flex-shrink available in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS flex-shrink Property for the fast development of the front-end. This class specifies how much the item will shrink compared to other items inside that container.
2 min read
CSS flex-shrink Property
The CSS flex-shrink property specifies how the item will shrink relative to the remaining flexible items inside the same container. It is essential for responsive design, allowing elements to reduce their size based on available space. This property does not affect non-flexible items. Note: If the item in the container is not flexible then the flex
2 min read
Bootstrap 5 Flex Grow and shrink
Bootstrap 5 Flex Grow and shrink is used to apply the expanding and shrinking look to an HTML div in a flexbox. By default, all the flex items will have the width/size until specified. When we add the .flex-grow-1 to a flex item it expands and covers up all the space which is available to it. Adding the .flex-grow-0 will keep the width of the flex-
3 min read
What is the difference between display:inline-flex and display:flex in CSS ?
In this article, we will see the display property &amp; its values, i.e. the inline-flex &amp; flex, in order to specify the display behavior of an element, along with understanding their basic differences &amp; will illustrate them through the examples. Both CSS display: inline-flex and display: flex properties are used to create flexible layouts.
3 min read
Bootstrap 5 Flex Enable Flex Behaviors
Bootstrap 5 Enable Flex Behaviors are used to apply display utilities to create a flexbox container and transform direct children elements into flex items. With more flex properties, flex items and containers can be further modified. Utility classes: .d-flex: It displays an element as a flex container..d-inline-flex: It displays an element as an in
2 min read
Shrink Text on Hover using HTML and CSS
Text can be Shrinked or condensed using some HTML and CSS properties, you can use this animation in your websites as headings or sub-headings, the below sections will guide you on how to create the desired effect. HTML Code: In this section we have simple div element which contains the text separated with span tags. C/C++ Code &amp;lt;!DOCTYPE html
2 min read
How to Create Shrink Header on Scroll using HTML, CSS and JavaScript ?
The Shrink Navigation bar works when the user scrolls down the page. In this article, we will use HTML, CSS, and JavaScript to design a shrink navigation bar. HTML is used to create the structure, and CSS is used to set the style of the HTML structure to make it looks good. This kind of shrinking navbar looks attractive on a site. By using JavaScri
3 min read
How to Create a Summary Element that can Expands but never Shrink using HTML ?
In this article we are going to learn How to create a summary Element that can Expand but never shrink using HTML,It can be seen in many websites like reading more buttons containing a link. These things expand when the user clicks the read more link or button then after expanding there was no option for collapsing the expanded content. In this art
2 min read
How to make container shrink-to-fit child elements as they wrap?
A Flexible Layout must have a parent element having display property set to flex. Direct child elements of the flexible container automatically become flexible items. Approach: The element below represents a flex container with four flex items. &lt;div id=&quot;container&quot;&gt; &lt;ul&gt; &lt;li&gt;icecream&lt;/li&gt; &lt;li&gt;sandwich&lt;/li
2 min read
three90RightbarBannerImg