The image remains contained within the boundaries of the container without overflowing

Working on a vue Project utilizing tailwind for styling, I have a flexbox layout that includes two custom components. The second component is an image that should maintain its size and not shrink or distort when the screen size is reduced. Instead, it should narrow the viewable area horizontally, allowing the user to scroll left and right to see the complete image.

To achieve this, I believe the proper method is to assign fixed dimensions to the outer div, set it to display as a block, and enable horizontal overflow scrolling. The image should have full height and width properties so that when the container is resized, it will overflow as needed.

However, I am encountering an issue where the entire image is shrinking when the container is narrowed.

  <div class="flex xl:flex-row flex-col">
    <ComponentOne
      class="h-128"
    ></ComponentOne>
    <ComponentTwo class="h-full block max-h-[43rem] max-w-[83rem]  overflow-x-scroll"></ComponentTwo>
  </div>

The code for Component Two is as follows

<template>
  <img class="h-full w-full" src="../assets/image.png" />
</template>

Answer №1

If you're aiming to achieve a specific design, you need to separate the wrapper element from the content element. Having them as one element won't allow for overflow and scroll functionality.


To illustrate further, consider the following code snippet for <ComponentTwo />'s template:

<template>
  <img class="h-full w-full" src="../assets/image.png" />
</template>

When you use the code:

<ComponentTwo class="h-full block max-h-[43rem] max-w-[83rem] overflow-x-scroll"></ComponentTwo>

it effectively results in:

<img class="h-full block max-h-[43rem] max-w-[83rem] overflow-x-scroll w-full" src="../assets/image.png" />

This happens because <ComponentTwo /> will be replaced with its template contents, inheriting its classes. In this case, the classes are applied to the <img> element.

To correct this, consider updating the template to:

<template>
  <div>
    <img class="h-full w-full" src="..." />
  </div>
</template>

Alternatively, wrap <ComponentTwo /> in a <div> with the desired overflow classes.


Additional suggestions:

  • Consider adding classes w-auto and h-auto to the <img>
  • Try using .overflow-x-auto instead of .overflow-x-scroll
  • Always double-check the output, especially the resulting DOM elements.

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

Half of the sections will not stack on mobile devices

UPDATE I found and fixed a typo in the code, making adjustments to both the JSFiddle and this post to show the correction. The Headline is supposed to take up 100% height but currently isn't. Still seeking feedback on this issue. Everything looks per ...

Determine the selected item's value in a Vuetify multiple selection component

In my code, there is a v-select component with the following configuration: <v-select v-if='d.length' v-model='ci' :items='d' item-text='value.name' item-value='value.name' label ...

What's the best way to center and expand a Bootstrap 5.3 dropdown menu to fill the entire width of the page?

I want to recreate the dropdown menu seen on this page, with the full width of the page but without any content. Additionally, I need all the "lorem" links in the menu to be centrally aligned in the navbar. Unfortunately, I am unable to modify the bootstra ...

Transmit information between Vue components

Hey there, I'm facing an issue with sending data from one component to another and could really use some guidance on how to tackle this. The scenario is that I have a component which iterates through an array of items and displays them. Then, there&a ...

Align the date input field to the center for better visual appeal

I am facing a challenge in centering the date in an input, not the entire input element inside a div. When I attempt to center it, the date gets positioned within a portion of the input due to a resizable right-hand side panel for selecting a date from a c ...

Sending new props when navigating back using $navigateBack

I created an overview page where users can view their results. They have the option to edit a value by clicking on the edit button, which navigates them to another page for making changes. However, upon returning to the overview page after editing, I notic ...

Duplicate user scrolling input within a specified div container

I am attempting to recreate a horizontal scrolling effect on a div element that mirrors the input scroll. When the user scrolls along the input, I want the div element to scroll in sync. The issue I am encountering is specific to Chrome, where the input b ...

Error occurs when SRCSET loads the wrong size because "sizes" parameter is missing

According to the guidelines, when sizes is not specified in the image attribute, the browser should automatically calculate the required size based on CSS rendering. In this scenario, my image is 300px and the browser should select the 300px image. Howeve ...

Is there a way to modify the text color within the thumb-label of the Vuetify v-slider component?

Lately, I've been facing some challenges and my objective is to change the color of the thumb label on my v-slider to a custom one that is defined in the component's design. Can anyone provide guidance on how to achieve this? Regards, Joost ...

Employing the html.validationmessagefor to display a client-side error notification

My text fields have server-side validation messages. The field 'title' is a required field on the server side with a '[Required]' data attribute in the class, but it only seems to be checked on a postback or form submit. I am saving the ...

The requested resource at http://localhost/Grafica/%7Bd.icon%7D/ was not found (Error 404)

Creating a tooltip in a weather chart, I want to display an image of the sky condition. Below is the HTML code: <div id="tooltip"> <table class="table table-condensed"> <tr><th>Time (local)</th><th data-text="d ...

Tap to navigate to queued sections on click

Greetings, community members! Despite my extensive research, I have been unable to find a solution to my query. Just a heads up - I am a novice when it comes to javascript and jQuery. My question pertains to incorporating two image buttons that, upon cli ...

Convince me otherwise: Utilizing a Sinatra API paired with a comprehensive JS/HTML frontend

As I embark on the journey of designing a social website that needs to support a large number of users, I have come up with an interesting approach: Implementing Sinatra on the backend with a comprehensive REST API to handle all operations on the website ...

Is there a more efficient method for showcasing model objects in Thymeleaf rather than utilizing a form?

I've been exploring Spring Boot, Thymeleaf, and frontend development in general. Currently, I have a frontend table that displays a list of objects from the backend, along with a form to allow users to view properties of each item in the list. Howeve ...

Puzzled by the CSS Box Model - There's a piece of the puzzle I

Check out my simplified fluid layout right here at this link. I've been trying to figure out why the alignment between the right column and the header above it seems off, even though there's no padding involved. Both have the same border styles, ...

Trigger AJAX request upon selecting a value from the dropdown menu

I am in the process of creating a basic dropdown menu that is only visible to users on mobile devices when they visit our website. The main objective is to allow users to select a value and then have that value sent via AJAX. For desktop devices, I have s ...

What could be the reason for a jQuery script failing to execute when included in a PHP include statement from a different PHP page?

I'm currently working with javascript and php to manage cookies across different pages. On one page, I have a script that sets a value in a cookie variable and I want to retrieve that value on another page. Let's say the first page is named page1 ...

Unable to retrieve information from a function in Vue.js (using Ionic framework)

When attempting to extract a variable from a method, I encounter the following error message: Property 'commentLikeVisible' does not exist on type '{ toggleCommentLikeVisible: () => void; This is the code I am working with: <template& ...

Ways to position two buttons in each corner with flexbox in a react js application

I'm fairly new to React JS and have just started building a simple React app. I'm trying to place two buttons on each side using CSS flex, but I'm having trouble achieving it. Can anyone help point out where I might be going wrong? im ...

Here's how you can pull information from a MySQL database and showcase it on an HTML

I successfully created a database in MySQL where users can enter their details on /upload.html, which then get stored in the test2 database and person_list table. However, I am facing an issue with displaying this data on /download.html. My goal is to hav ...