Exploring optimal image sizes within Flexbox layouts

I need some assistance with my Next.js 13 and Tailwind website. I am currently facing an issue with flexbox sizing that I can't seem to figure out. My objective is to have two FlexboxItems with equal width on medium and larger screens, and equal height on smaller screens. The one with the width on larger screens seems to be working fine, but on smaller screens, the items are not of the same height.

<div className=" bg-slate-500 min-h-screen flex md:flex-row flex-col">
           <div className="bg-orange-400 flex-1 flex flex-col justify-center content-center flex-wrap text-4xl">
              <h1>Text</h1>
           </div>
           <div className="bg-lime-500 flex-1 flex flex-col justify-center">
              <Image
                 src={FreeSquareImg}
                 alt="Sample"
                 className="rounded-3xl"/>
           </div>
  </div>

https://i.sstatic.net/gdUIY.png

https://i.sstatic.net/FP02a.png

Answer №1

To make sure the image does not extend beyond the green div, you can set both the div and the image to have equal height with h-1/2.

Here is the code that will help you achieve this:

<script src="https://cdn.tailwindcss.com"></script>
<div class="flex h-screen flex-col bg-slate-500 sm:flex-row">
  <div class="flex h-1/2 flex-1 flex-col flex-wrap content-center justify-center bg-orange-400 text-4xl">
    <h1>Text</h1>
  </div>
  <div class="flex h-1/2 flex-1 flex-col justify-center bg-lime-500">
    <image src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" alt="Sample" class="mx-auto w-1/2 rounded-3xl sm:w-full sm:p-12" />
  </div>
</div>

You can also see how it looks on mobile and other screen sizes here

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

Using codedeploy to deploy a Next.js application onto an AWS EC2 instance

After creating a fresh NextJS app with only basic boilerplate files and folders, I uploaded it to a CodeCommit repository. I already had a functional CodePipeline and simply switched the Source stages. However, I am encountering deployment failures during ...

Is it possible to load data only once in Next/React?

Utilizing Next for my website, I am seeking a way to retrieve data from an API that only needs to be loaded once for the application. Is there a method to fetch the data again only when a true reload occurs? I attempted to load the data in my _app.js fil ...

Switching the image on click of an option tag

I'm looking to create a dynamic image changing feature using two select tags in my HTML. One select tag is for the model and the other is for the color. When a user selects a model from the first dropdown, I want the image to change to reflect that mo ...

What are some effective ways to utilize CSS translateZ?

I'm attempting to create a new layer of content with CSS, but I'm having trouble adjusting the depth of the element using the translateZ property. I tried using some codepen code to achieve a 3D effect. Below is the HTML, CSS, and Javascript cod ...

Next.js - Anticipated that the server HTML would include a corresponding <div> within <div> tag

For a live demonstration, please click here In my current project, I am experimenting with creating a simple layout that adjusts based on the user's screen size. Specifically, on mobile devices, only the latest posts should be displayed. On desktops, ...

Form validation using ajaxSubmit with a pop-up to display a "processing" div

Currently, I have set up ajaxSubmit on my web form. Along with this functionality, I want to implement a pop-up div that displays a message saying "Processing the request" along with a dimmed background when the user clicks on the submit button. This is t ...

Guide to adding customized CSS and JavaScript to a specific CMS page on Magento

I'm trying to incorporate a lightbox for video playback on a specific page of my CMS. I've placed my CSS file in JS/MY THEME/JQUERY/PLUGIN/VENOBOX/CSS/myfile.css and the JS files in JS/MY THEME/jquery/plugins/venobox/js/myfile.js, but it doesn&ap ...

What is the best way to set up a HTML redirect page with Google Analytics code inserted into it?

Is it possible to generate an HTML page that redirects to a subfolder, yet maintains the Google Analytics code block for tracking on the homepage? ...

After updating from version 1.7 to 1.8.1, certain css styles in Magento are not displaying

I opted to use FTP for upgrading Magento as I lack the technical skills to navigate SSH. Initially, I came across the 500 internal server error, followed by the blank page Google Checkout error. After resolving those, I am now dealing with a missing style ...

What is the best way to organize CSS rules for individual files in a React project?

In my ReactJS project, I am currently developing a landing page and an articles page. However, I've encountered an issue where the CSS styles applied to the landing page are impacting the layout of the articles page. I suspect that this is happening b ...

Populating checkboxes by inserting data from an array

Currently, I have a set of checkboxes where I am storing the values in an array: <ul> <li><input type="checkbox" name="daily[]" value="0"></li> <li><input type="checkbox" name="daily[]" value="1"></li> ...

What is the method for obtaining touch coordinates within iOS Safari?

Trying to use the following code snippet to fetch touch coordinates on iOS Safari: $('#touchable').bind('touchstart', function(e){ alert(e.touches[0].pageX); alert(e.touches[0].pageY); } However, upon testing, I am fa ...

Adapting my desktop website layout to be responsive for an optimal viewing experience on iPads and mobile

I recently created a webpage for laptop view and attempted to use media queries to adjust the CSS styling to fit on iPad and mobile devices. However, when setting the width of the (.content) element to 100%, the content doesn't actually fill the entir ...

In the thymeleaf fragment, the th:field attribute is marked with a crimson underline

I am facing an issue with a fragment that opens a modal when a button is clicked. Inside the modal, there is a form with a text field for token and submit button. However, I am getting a red squiggle underneath the th:field attribute "token", and I'm ...

Guide on incorporating the WHERE clause into an insert statement in PHP version 5.1.6

What is the correct way to incorporate a where clause into an insert statement in PHP 5.1.6? In my code, I have declared a global variable $module and I am trying to use a where clause to refine my search results. Specifically, I want to include where mod ...

Fixed top Bootstrap navbar - featuring a logo on the left and navigation links on the right

Having trouble creating a responsive fixed navbar with logo and navlinks on both sides. I removed all Bootstrap elements from the code I'm sharing here, can someone help me out? I need a solution using Bootstrap to ensure everything is responsive. Th ...

Prevent CSS from resizing text to the very bottom of the page

My goal is to prevent text from overflowing all the way to the bottom of the page, as I need a space for another div at the end. How can I create a gap between the text and the bottom of the page? Additionally, how do I restrict the size and position of t ...

How can the top height of a jquery dialog be reduced?

Just starting out with jquery, I've got a dialog box and I'm looking to decrease the height of this red image: https://i.sstatic.net/BuyQL.png Is there a way to do it? I've already made changes in the jquery-ui.css code, like so: .ui-dia ...

Utilize CSS in your HTML using Express framework

I am attempting to link a css stylesheet to my basic html webpage. I am utilizing parse.com hosting for dynamic webpages that utilize express. There are numerous responses to this question, but none of them have proven successful in my case. I am trying ...

Javascript keycode used to target the element when a key is pressed

In my current project, I am utilizing a code snippet to attach a KeyDown event handler to any element within the HTML form. for(var i=0;i<ele.length;i++) { ele[i].onkeydown = function() { alert('onkeydown'); } } I am ...