Is there a way to dynamically adjust the height and width of a div based on the movement of the mouse pointer?

Here is how my div looks: https://i.sstatic.net/2A4vL.png

I came across some discussions on stack overflow but couldn't quite grasp how to implement it in my project. Imagine if I move the mouse pointer between column1 and column2, I want an arrow to appear and adjust the width based on the mouse position. Similarly, if I hover between column2 and column3, I want the height of column2 and column3 to automatically adjust. Here's a snippet of my react code:

const test = () => {
  return (
    <div className="container">
      <div className="column1">
        <div className="content">
          <h2>Column 1</h2>
          {/* Add content for Column 1 here */}
        </div>
      </div>
      <div className="column2">
        <div className="content">
          <h2>Column 2</h2>
          {/* Add content for Column 2 here */}
        </div>
      </div>
      <div className="column3">
        <div className="content">
          <h2>Column 3</h2>
          {/* Add content for Column 3 here */}
        </div>
      </div>
    </div>
  );
};

And this is my CSS:

.editor {
  display: grid;
  /* Adjust the grid-template-columns to allocate less space to the first column */
  grid-template-columns: 1fr 2fr; /* You can adjust the values as needed */
  grid-template-rows: 2fr 1fr;
  gap: 10px;
  height: 100vh;
}

.column1 {
  grid-column: 1;
  grid-row: 1 / span 2;
  border: 1px solid #ccc;
  padding: 10px;
  overflow: auto;
}

.column2 {
  grid-column: 2;
  grid-row: 1;
  border: 1px solid #ccc;
  padding: 10px;
}

.column3 {
  grid-column: 2;
  grid-row: 2;
  border: 1px solid #ccc;
  padding: 10px;
}

Answer №1

If you are looking to implement resizable columns in React, consider using the react-split library as suggested by Keith. Here is a simple example demonstrating how you can achieve this:

import Split from 'react-split';

const ResizableColumns = () => {
  return (
    <Split
      sizes={[30, 40, 30]} // Initial column sizes in percentages
      minSize={100} // Minimum size for columns
      expandToMin={false} // Disable expanding columns to their minimum size
      gutterSize={10} // Size of the draggable gutter
      gutterAlign="center" // Align the gutter to the center
    >
      <div className="column1">
        <div className="content">
          <h2>Column 1</h2>
          {/* Content for Column 1 goes here */}
        </div>
      </div>
      <div className="column2">
        <div className="content">
          <h2>Column 2</h2>
          {/* Content for Column 2 goes here */}
        </div>
      </div>
      <div className="column3">
        <div className="content">
          <h2>Column 3</h2>
          {/* Content for Column 3 goes here */}
        </div>
      </div>
    </Split>
  );
};

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

Leveraging Iframes for efficient user authentication within an Angular application

Incorporating an Iframe into one of my templates for authentication has presented certain challenges. Case in point: When a user finishes a training session, they must verify their identity by authenticating with a ping identity server that will redirect ...

Creating a slanted or tilted button in CSS and web design

Is there a way to create a website button that has oblique (diagonal) sides on each side? I haven't been able to find an exact example, but I did come across a similar design in about 10 minutes: (check out the menu tabs for News, Video, Schedule, ...

Tips for applying an active class to buttons using ng-click?

Here is the HTML code for the buttons. The taskfilter is the filter that controls how the buttons work when clicked and the class name is 'sel' <a class="clear-completed" ng-click="taskfilter = 1" ng-class="{'sel':enabled}"> &l ...

The alignment of the Bootstrap Radio white circle is off when adjusting the HTML font size

I'm currently working on a simple web application using Bootstrap for styling. While I really like the overall look of Bootstrap, I've run into an issue with the appearance of my radio buttons when I adjust the font size in my HTML. Here is a sn ...

The validation for "classes" in props is not found - Linting issue

Today I encountered an issue with the linting process. It has always functioned properly, but now it is flagging an error related to the props "classes" when using React Hooks. My components are structured like this: import { withStyles, WithStyles } from ...

Is there a way to deactivate middleware in Node, Express, and Mocha?

My application features a hello world app structured as follows: let clientAuthMiddleware = () => (req, res, next) => { if (!req.client.authorized) { return res.status(401).send('Invalid client certificate authentication.'); } ret ...

Which is more efficient: sending individual XMLHttpRequests to multiple scripts or consolidating requests in one master script for task delegation?

I am currently developing a large-scale web application using javascript and PHP. The application involves various types of XMLHttpRequests, and I'm contemplating the best approach: should I direct each request to separate PHP scripts or use one centr ...

Watching an array of objects in AngularJS with assigned indices

I'm seeking guidance on how to utilize Angular watch with an array of objects. Here is an example array $scope.chartSeries containing objects like this: [{"location": {values}, "id":"serie-1", "meter":{values}, "name": "seriename", "data":[{1,2,4,5, ...

What is the best way to share HTML code among multiple HTML documents?

It's always a pleasure to connect with everyone. I've explored numerous solutions online, but I haven't found the desired outcome yet. Currently, I am working on writing Bootstrap code in HTML files using the template from adminlte.io. Al ...

No value found for Req.file using the express-fileupload and multer libraries

I have exhausted all possible scenarios and attempted various variations and methods recommended in the documentation and from other sources like Stack Overflow. However, none of them seem to work -> I constantly receive req.file is: undefined Here is ...

Display a fixed three levels of highchart Sunburst upon each click in Angular8

Looking to create a dynamic sunburst highchart that displays three levels at a time while allowing interactive drilling. For instance, if there are 5 levels, the chart should initially show the first three levels. When clicking on level 3, levels 2, 3, and ...

I'm encountering an issue where I receive the error `Cannot read property 'map' of undefined` while attempting to integrate the backend with React. What could be causing this error and how

I'm currently learning React and I've been using a tutorial here to connect my database to the front end of my React application. Unfortunately, every time I try running 'npm start' at 'localhost:3000' in express-react/backend ...

Optimize top margin spacing for Ant Design Tag component

I'm currently utilizing the antd Tag component, which comes with the property display: inline-block; causing some unwanted top margin. I am looking for a way to eliminate this extra margin without having to introduce an additional container for the ta ...

Add a .handlebars or .hbs file to an HTML document

When visiting the emberjs.com homepage, you will find an example of a todo list using Ember.js and Handlebars.js. Within the todo list, there is an extension for a .hbs file. I am curious - what exactly is a .hbs file? And how can I include a .hbs script ...

Mastering the Art of Loading "Please wait" Messages with jQuery BlockUI on Your Website

I'm seeking assistance with implementing jQuery blockUI in my application. Below is the code I currently have: $.blockUI({ css: { border: 'none', padding: '15px', backgroundColor: '#000 ...

The AngularJS UI router is encountering an unexpected error: GET request not recognized

Need help with AngularJS Routing using UI-Router. My index.html file is attempting to load the partial productListView.html using app.js as javascript, but I'm encountering an error: "Unexpected request: GET productListView.html" in the console. Any a ...

Getting input elements with Puppeteer can be done by waiting for the page to fully load all elements within the frameset tag

Seeking to gather all input elements on this website: This is how the element source page appears. Below is my code snippet: const puppeteer = require("puppeteer"); function run() { return new Promise(async (resolve, reject) => { try { ...

Is there a way to update a label on a webpage in real-time according to the text entered in a textbox?

I am in the process of designing a more user-friendly input form where I prompt the user to enter their name in a text box. Based on the information they type in, I would like to display this information a little further down the page to add a personal tou ...

Can you identify the issue in this code?

I am facing an issue with using this code to save values in a table when the page loads. The function that searches for values is written in PHP, and I need to use these values in my script. Unfortunately, the current approach I am trying doesn’t seem ...

Access the data within a jsonArray using Cypress

I'm dealing with a test.json file that contains a jsonArray [{ "EMAIL": "email_1", "FIRST_NAME": "Daniel" }, [{ "EMAIL": "email_2", "FIRST_NAME": "John" }] ] I'm trying to figure out how to use cypre ...