Ensure that the image scales proportionally to match the dimensions of the surrounding text

Currently, I am in the process of working on a Shopify website and I am faced with an issue regarding the scaling of images to match the size of the text. Here is what it looks like at the moment: Image depicting the discrepancy between image and text sizes

Below is the code snippet that I am currently using.

<div class="bulky-img-section-right">
{%else%}
<div class="bulky-img-section">
{%endif%}
    <div class="image-sub-section">
        <img class="is-image" src="{{section.settings.image-link | img_url:'master'}}" alt="{{section.settings.image-link}}" />
    </div></div>

CSS

    .bulky-img-section
{
    display: flex;
    flex-direction: row;

    width: 100%;

}

.bulky-img-section-right
{
    display: flex;
    flex-direction: row-reverse;

    width: 100%;
}

.image-sub-section
{
    width: 50%;
    
    padding: 3rem;
}

I appreciate any help or guidance provided. Thank you.

Answer №1

If you want to take the image out of the normal flow, you can achieve that by using absolute positioning.

:root {
  --imageGap: 3rem;
  --imageSize: calc( 50% - var(--imageGap) );
}

.bulky-img-section {
  display: flex;
  align-items: stretch;
  gap: var(--imageGap);
}
.bulky-img-section:not(:last-child) { margin-bottom: var(--imageGap) }

.image-sub-section {
  position: relative;
  max-width: var(--imageSize); min-width: var(--imageSize);
}
.image-sub-section .is-image {
  position: absolute;
  height: 100%; width: 100%;
  object-fit: cover;
  object-position: center;
}

.right .text-sub-section { order: -1 }
<div class="bulky-img-section">
  <div class="image-sub-section">
    <img class="is-image" src="https://picsum.photos/id/1/200/1000" alt="Some random picture" />
  </div>
  <div class="text-sub-section">
    <p>Eros nisi mi nec natoque erat egestas pharetra dui eu interdum vestibulum est porttitor consectetur a lectus parturient justo fringilla dis a eros dui torquent curabitur molestie dignissim. Ac vestibulum suspendisse a enim tempus accumsan vestibulum nam proin parturient nunc suspendisse adipiscing lacinia a gravida tellus ridiculus a ac at etiam fringilla parturient quis malesuada sociis neque. Ultrices arcu blandit id vestibulum suspendisse a etiam a non condimentum facilisis senectus dapibus suspendisse curae. Ligula parturient mollis natoque a a mauris turpis nec dis dui rutrum suspendisse ad eget mus a sodales blandit.</p>
    <p>Gravida scelerisque neque magnis parturient commodo parturient nostra duis a ullamcorper a orci elementum nec mus bibendum justo a. Purus iaculis cubilia pharetra egestas orci rutrum auctor a ut elit himenaeos fames sociosqu eu sed a a senectus aliquet. Rhoncus aliquam erat a nibh nibh mollis suspendisse dui a risus elit nunc dictum a. Aenean integer orci arcu erat varius inceptos pulvinar condimentum etiam mauris purus dui consequat id ipsum odio semper blandit. Vulputate eleifend venenatis ridiculus metus massa non a sed et nunc dolor potenti adipiscing per cras natoque a fermentum ac varius vehicula a a quam vulputate blandit cum. Ad ullamcorper auctor a nam urna phasellus parturient a vestibulum elit fermentum mi dictumst a consectetur nisi id fames.</p>
  </div>
</div>

<div class="bulky-img-section right">
  <div class="image-sub-section">
    <img class="is-image" src="https://picsum.photos/id/2/200/1000" alt="Some random picture" />
  </div>
  <div class="text-sub-section">
    <p>Eros nisi mi nec natoque erat egestas pharetra dui eu interdum vestibulum est porttitor consectetur a lectus parturient justo fringilla dis a eros dui torquent curabitur molestie dignissim. Ac vestibulum suspendisse a enim tempus accumsan vestibulum nam proin parturient nunc suspendisse adipiscing lacinia a gravida tellus ridiculus a ac at etiam fringilla parturient quis malesuada sociis neque. Ultrices arcu blandit id vestibulum suspendisse a etiam a non condimentum facilisis senectus dapibus suspendisse curae. Ligula parturient mollis natoque a a mauris turpis nec dis dui rutrum suspendisse ad eget mus a sodales blandit.</p>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to implement Ionic components on a website without using the Ionic framework?

Having utilized and appreciated Ionic for many mobile apps, I am now in the process of creating a web client for my application. It has come to my attention that Ionic was not designed for desktop applications. However, I am curious if I can still utilize ...

Ensuring the endpoint of a right chevron Font Awesome icon aligns perfectly with the edge of a div

Is there a way to position a font-awesome chevron icon or right arrow icon in such a way that its point touches the edge of the containing div perfectly? Despite using text-align: right, the icon still seems to have some spacing to the right preventing it ...

Block Button styles not displaying in IE when set to Full Width

I can't figure out why, but it seems to be functioning properly on every other internet platform except this one. The first picture shows the button in IE, the second contains the code, and the third displays the button in Chrome. https://i.sstatic. ...

Safari IOS experiencing issue with element disappearing unexpectedly when input is focused

I am facing a situation similar to the one discussed in the question (iOS 8.3 fixed HTML element disappears on input focus), but my problem differs slightly. My chatbox iframe is embedded within a scrollable parent, and when the iframe is activated, it exp ...

Issues with 'floating' unordered lists

.menu li { float: left; color: #fff; font-weight: bold; } .menu li a { display: block; height: 20px; min-width: 110px; text-decoration: none; border-radius: 3px; padding: 4px; padding-left: 6px; padding-right: 6p ...

How to stop the parent element from activating :active pseudoclass when the child element is clicked using CSS

JSFiddle Upon clicking the button, it is noticeable that the :active pseudoclass is activated for the parent div. Is there a way, using only CSS (or any JavaScript library), to prevent the :active pseudoclass from being triggered when the button is clicke ...

The issue regarding the fixed table layout bug in Firefox

Upon testing Firefox 5, it has come to my notice that an additional pixel of space is being added between the right column and the table border due to this particular piece of code: <style type="text/css"> table { border: 1px s ...

Pause jQuery at the conclusion and head back to the beginning

As a beginner in the world of jQuery, I am eager to create a slider for my website. My goal is to design a slideshow that can loop infinitely with simplicity. Should I manually count the number of <li> elements or images, calculate their width, and ...

My HTML gets rearranged by browsers, causing a change in appearance

UPDATE: I have discovered that the issue lies with Internet Explorer which alters the class attribute of an HTML element from: "<img class="blah".." to "<img class=blah..". This inconsistency only occurs in IE for me. It does not affect other attr ...

Tips for optimizing the responsiveness of your React component

I am facing an issue with making our website responsive and applying CSS to it. I have shared the UI code below for reference. Please review it and provide a solution as soon as possible. I need to ensure that this cat girl picture and text are responsive ...

Tips for adjusting column spacing in HighCharts

Looking for some advice on how to make a chart container scrollable and properly space the labels and bars within a parent container with fixed width and height. The goal is to ensure all labels are visible and bars are well spaced. Any suggestions or tips ...

Java - Changing Font Size in HTML JTextPane with CSS Styling

When utilizing the following code snippet: Action sizeAction = new StyledEditorKit.FontSizeAction(String.valueOf(size), size); The button associated with the action adds the HTML tags: <FONT SIZE="5"> My text here </FONT> Utilizing these ta ...

What is the best way to create a responsive Material UI Modal?

I have set up a Modal with a Carousel inside, but I am struggling to make it responsive. Despite trying various CSS solutions from StackOverflow, nothing seems to be working for me. How can I resolve this issue? CSS: media: { width: "auto&quo ...

Create a dynamic and adaptable Google Maps experience without the need for an iframe

For instance, if you are using an embedded Google Map. You can ensure that your Google Map is responsive with the following code: Using iframe (simple iframe) <div class="ggmap"> <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m ...

Allowing the primary content to span the entire width of the mobile screen

I have scoured various forums in search of answers, but unfortunately, I haven't found a solution that fits my specific query. I am looking to ensure that the .main-content (article text and images) occupies the full width of the mobile screen without ...

What steps can be taken to ensure that the content in column two does not impact the positioning of content in column one?

Is there a way for the input text container to remain in its original position within the layout even after submitting text? Usually, when the data displayed container's height increases, it pushes the input text container down. Despite trying absolu ...

Ways to implement a parallax effect by changing images within a specific div on scrolling with the mouse

First and foremost, thank you for taking the time to review my question. I am currently developing a website and I need to implement a vertical image transition effect within a selected division, similar to a parallax effect. Within this div, there are 3 ...

Creating a popup with multiple tabs using CSS

Struggling to navigate through the intricacies of these code snippets <!DOCTYPE html> <html lang ="en"> <head> <style type="text/css"> a{ text-decoration:none; color:#333; } #pop{ width:557px; height:400px; background:#333; ...

Break the line after every space in words within an element

I have a table/grid view with two words in the <td> like "C2 Sunday". I need a line break after C2 so that it appears as: C2 Sunday Is there a way to achieve this? Please assist me with this issue. Currently, it is showing as "C2 Sunday" and I wou ...

CSS responsive grid - adding a horizontal separator between rows

I currently have a responsive layout featuring a grid of content blocks. For desktop view, each row consists of 4 blocks. When viewed on a tablet, each row displays 3 blocks. On mobile devices, each row showcases 2 blocks only. I am looking to add a ho ...