Struggling to design a responsive layout as the div on the right keeps overlapping the div on the left

I recently built a React component that consists of two columns. In the left column, there's a calendar while the right column contains some text along with an input and select field.

However, I noticed that when I resize the window, the elements on the right start moving towards the left, eventually overlapping with the calendar.

I'm now trying to find a solution where the content remains intact and gracefully adjusts as the window size decreases, rather than overlapping each other.

https://codesandbox.io/s/blue-bash-32xik?fontsize=14

import React, { Component } from "react";
import ReactDOM from "react-dom";
import { Col, Row } from "antd";
import styled from "styled-components";
import "antd/dist/antd.css";
import Calendar from "./Calendar";

class App extends React.Component {
  render() {
    return (
      <div className="App">
        <Row>
          <Col span={12}>
            <Calendar className="myClassname" />
          </Col>
          <Col span={12}>
            Selected Date: <input />
            <TimeSelection>
              Available Times:
              <select size={3}>
                <option>AM</option>
                <option>PM</option>
                <option>ANY</option>
              </select>
            </TimeSelection>
          </Col>
        </Row>
      </div>
    );
  }
}

const TimeSelection = styled.div`
  margin-top: 10%;
`;

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Answer №1

Encountering a Responsive Issue with calendar size being statically applied? Utilize the following CSS code snippet to address this problem. Simply add the provided CSS into the Calander.css file at the bottom.

/* Adjust calendar to fit column */ 
.react-datepicker,
.react-datepicker__month-container {
  width: 100%;
}
/* Modify calendar column width dynamically */ 
.myClassname,
.react-datepicker__day-name,
.react-datepicker__day,
.react-datepicker__time-name {
  width: 12%;
}

Answer №2

After reviewing your CodeSandbox example, it appears that the main issue lies in the fixed width of the calendar component. While the column widths function correctly, the calendar does not adjust accordingly, giving the impression of content overlap.

If you refer to the antd documentation on responsive Grid, you can implement different column spans based on screen sizes. For instance:

<Row>
  <Col xs={24} md={12}>
    <Calendar className="myClassname" />
  </Col>
  <Col xs={24} md={12}>
    Selected Date: <input />
    <TimeSelection>
      ...
    </TimeSelection>
  </Col>
</Row>

Setting each column's span to 24 at the smallest size (xs) will make them occupy the entire width, causing them to stack vertically. Then at the md size, both are set to a span of 12 as currently done in your code.

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

Creating a CSS layout with three columns where the first column's width is unspecified and the second

I am looking to create a three column layout with specific width requirements. The first column should adjust based on content, the second column should fill the space between the first and third columns, and the third column should have a fixed width. Add ...

Retrieving User Keypad Input with Twilio Phone Calling in a Node.js Application (excluding web server)

const userInput = message.content.split(' ') const phoneNumber = userInput[1] const messageToSay = userInput.slice(2).join(' ') if (phoneNumber) { // Dial phoneNumber and deliver messageToSay, then gather ke ...

How to add dimensions to a background image using CSS3

I would like the background image to have a size of 636px by 1140px instead of applying it to the div element directly. This is because I want to avoid scrollbars due to the height of the div. When I specify the width and height for the parent div, the ba ...

Vanish Dropdown upon clicking Using JavaScript

Hey, I'm new to web development and I'm currently working on creating a web app for iPhone. Everything is going smoothly except for one issue - my dropdown menu works perfectly on desktop Chrome, but on the iPhone's Safari browser, I can&ap ...

Tips for retrieving a value from a callback function?

How do I return a value from a callback function? The following code snippet is what I have: function storeData(data) { const id = "5f354b7470e79f7e5b6feb25"; const body = { name: "john doe" }; bucket.insert(id, body, (error, r ...

Having trouble resolving the 'crypto' module error after using xlsx-populate in React JS? Here's how to fix it!

Recently, I encountered an issue when using the xlsx-populate package in my React JS application. Compiled with problems: ERROR in ./node_modules/xlsx-populate/lib/Encryptor.js 14:15-32 Module not found: Error: Can't resolve 'crypto' in &a ...

Troublesome tab key function in FireFox causing navigation issues

I'm facing an issue with the tab key focus on links in FireFox. Strangely, it's working fine in Chrome but in FireFox, it keeps looping within one element. For better understanding, I have created a demo showcasing this behavior specifically in ...

Using JavaScript, you can add an article and section to your webpage

Currently, I am utilizing AJAX to showcase posts. My objective is to extract each property from a JSON object that is returned and generate an <article> for the title followed by a subsequent <section> for the content. While I can successfully ...

Ways to monitor and measure clicks effectively

Within my website, I have a table element with one column and numerous rows. Each row serves as a hyperlink to an external shared drive. <tr><td ><a href="file://xxx">Staff1</a></td></tr> <tr ><td ><a h ...

Select the input element in CSS that does not have a parent with the class name 'classname'

In my stylesheet, I have a specific rule that styles various input fields and select elements. However, I'm facing an issue where this styling is being applied to all text fields on the page, including ones inside certain elements with a specific clas ...

Spicing up PHP data insertion into the database

I am working with two fields: one is a textarea and the other is an image field. <textarea name="siteplan" id="siteplan" class="form-control" rows="10"></textarea> The image field looks like this: <input type="file" name="image" id="image ...

Sift through JavaScript problems

My goal is to implement a filtering function on my input that will display a different result. However, I have encountered an issue where the this.data.stationInfo.stations array is being changed, as shown in the console.log output. According to the Mozil ...

How can you create a dynamic bounce effect for text with jquery animate()?

I've been experimenting with Jquery to achieve a bounce effect, here's what I have so far: Html: <div id ="animation">bounce</div> Jquery: $("#animation").animate({ marginTop: "80px" }, 1500 ) .animate({ marginBotto ...

Troubleshooting: React is not defined in Rollup + React 17 with updated JSX Transform

I'm currently working on prototyping a microfrontend architecture using Rollup and multiple create-react-app applications. However, when I try to locally yarn link my external app with the container app, I am encountering the following error: The err ...

tips for accessing variables within app.get

Is there a way to make a variable or a set of variables inside app.get accessible throughout the entire project? I am working on capturing information from an SMS text message, organizing it into the "messageData" variable, and then sending it to the "Mess ...

Uploading information to a server using Angular.js

I am currently working on developing an application with the following code snippet: function attendeeCtrl($scope, $http) { $scope.submit = function () { console.log($scope.noattendees); $http({ method: 'POST', ...

Trouble with background image displaying on meteor platform

Hey there! I'm in the process of replicating the HBO login page without functional links, but for some reason, the background image isn't loading properly. I suspect it might be an issue with resizing the image, but I can't pinpoint the exac ...

The functionality of the JavaScript Array Map function is not meeting our expectations

I am encountering an issue with the Array.map function that is not behaving as expected. Below is a simplified example to help me understand where I am going wrong. Here is the code snippet in question: console.log(this.reportTestData) let data = this.rep ...

Troubleshooting image alignment problem within a flexbox display

Is there a way to align the two images so that the bottom right of the first image meets the top left of the second image? I'm struggling to figure out a solution, especially considering different browser sizes. Any advice or suggestions? .flexbox ...

The height map method for plane displacement is experiencing issues

The heightmap I have selected: Scene without grass.jpg map : Scene with grass.jpg map: https://i.sstatic.net/q6ScO.png import * as THREE from 'three'; import {OrbitControls} from 'three/examples/jsm/controls/OrbitControls.js'; import ...