Prevent individual elements from shifting around on browser resizing within a React form

Having issues with a React form that includes an image gallery and input fields.

import React, { Component } from 'react';
import ImageGallery from 'react-image-gallery';
import { Container, Row, Col, InputGroup, Button, FormControl, Form } from 'react-bootstrap';

const images = [
    {
        original: '/assets/images/products/colgantes.png',
        thumbnail: '/assets/images/products/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="71121e1d16101f05140231415f4344095f011f16">[email protected]</a>',
    },
    {
        original: '/assets/images/products/corazones.png',
        thumbnail: '/assets/images/products/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="60030f12011a0f0e051320504e5255184e100e07">[email protected]</a>',
    },
    {
        original: '/assets/images/products/take-me-to-the-beach.png',
        thumbnail: '/assets/images/products/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9aeefbf1ffb7f7ffb7eef5b7eef2ffb7f8fffbf9f2daaab4a8afe2b4eaf4fd">[email protected]</a>',
    },
];


class DetailedProduct extends Component {

    render() {

        return (
            <>
                <Container fluid>
                    <Row >
                        <Col md={{ span: 4, offset: 3 }} sm={{ span: 12, offset: 0}} >
                            <ImageGallery
                                    items={images}
                                    showNav=""
                                    showFullscreenButton=""
                                    showBullets=""
                                    showPlayButton=""
                                    thumbnailPosition="left"
                            />
                        </Col>
                        <Col md={3} sm={12} className="text-xs-center text-md-left" >
                            <h1>Product</h1>
                            <h3>$500</h3>
                            <p>Lorem Ipsum is simply dummy text from the printing and typeseting industrys</p>

                            <Form>
                                <Row >
                                    <Col sm={12} md={8} >
                                        <Form.Group controlId="color" >
                                            <Form.Label>Color</Form.Label>
                                            <Form.Control as="select" custom>
                                                <option>Rojo</option>
                                                <option>Negro</option>
                                                <option>Azul</option>
                                            </Form.Control>
                                        </Form.Group>
                                    </Col>

                                    <Col sm={12} md={4} className="inline-block">
                                        <Form.Group controlId="cantidad" >
                                            <Form.Label>Cantidad</Form.Label>
                                            <InputGroup >
                                                <InputGroup.Prepend>
                                                    <Button variant="outline-secondary"  >+</Button>
                                                </InputGroup.Prepend>
                                                <FormControl
                                                    placeholder="1"
                                                    aria-label="quantity"
                                                    aria-describedby="basic-addon2"

                                                />
                                                <InputGroup.Append>
                                                    <Button variant="outline-secondary" >-</Button>
                                                </InputGroup.Append>
                                            </InputGroup>
                                        </Form.Group>
                                    </Col>
                                </Row>

                            </Form>

                        </Col>
                    </Row>
                </Container>

            </>
        );
    }
}


export default DetailedProduct;

The issue arises when resizing the browser window, causing the buttons in the input field to move separately to different rows, breaking the structure. Attempts to adjust CSS for the form group have not been successful in keeping them together consistently. The desired outcome should resemble this:

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

Answer №1

If you want to ensure a minimum size, consider including the following rule:

min-width: 150px;

The value of 150px is just an example and may need to be adjusted based on your specific needs.

In cases where you have a group of elements within a class called input-group, it would be beneficial to create a separate class for additional styling customization.

Answer №2

Appreciate the assistance! Managed to resolve the issue by adjusting the flex column sizes based on screen resolution - used sm={12} md={6} lg={4}. Worked like a charm!

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

The error message "res.jwt is not a function" is commonly encountered when using Node

I kept receiving the error message: res.jwt is not a function I have installed jwt-express and imported it like this: import jwt from 'jwt-express' This is my auth.js file: import Account from '../services/account.js' import env from ...

Using the Jquery accordion function within google maps is limited to running only one time

After successfully creating a google maps page with markers generated from XML, I encountered an issue. The plan was to display event information in a div when a marker is clicked, along with attaching an accordion to the events data. Although the first cl ...

Collapsed Bootstrap navigation bar on mobile devices

Hello everyone, I am currently using the latest version of Bootstrap for my website. However, I have encountered an issue where the navigation collapses on mobile view. Could anyone provide assistance? Website: Below is a snippet of my HTML code: <he ...

"Learn how to position a div element below the header div and above the footer div while maintaining full height in

Recently delving into the world of reactjs, I find myself facing a challenge with a page that contains 3 distinct blocks formed by divs. Have a look at the layout on my page: My Page This is the code snippet I have worked on: return ( <div> ...

Ways to retrieve a property from the context

Looking to access a specific property from context in a single component. The code functions as expected in plain JS, but when converting to TypeScript in BooksCarousel.tsx, I encounter the error: Error: Property 'fetchBooks' does not exis ...

Observing a web page created by a Java Servlet

After receiving the provided code, I attempted to compile it using a customized version of Dr. Java. However, upon attempting to run the code, I encountered an error message stating: "Static Error: This class does not have a static void main method accepti ...

Using the v-for directive in Vue.js to loop through an array and display

Looking at the image provided, I am trying to access the content. I attempted to do so using element.comments.content, but it did not seem to work as expected. Here is the snippet of code: <div class="fil-actualites-container"> <div cl ...

Managing the result efficiently when asp.net mvc ModelState IsValid is false

My colleagues and I are currently working on a CRUD application using .net mvc4. The project involves rendering dynamic content through jQuery based on customer choices. One challenge we face is the need to create multiple hidden inputs to pass additional ...

Using vue-resource to intercept an ajax error and catching the "Uncaught (in promise)" exception

I am utilizing vue-resource to retrieve data from the server. In order to access the correct data, a user must possess a JWT token. If the token is invalid or has expired, a status code of 401 will be returned. Similarly, if a user attempts to reach a forb ...

Tips for avoiding divs from overlapping when the window size is modified

When I maximize the browser, everything aligns perfectly as planned. However, resizing the window causes my divs to overlap. Despite trying several similar posts on this issue without success, I have decided to share my own code. CODE: $(document).read ...

Trigger an input file click automatically using vanilla JavaScript with an AJAX request in Google Chrome

Currently, my webapp operates in a way that every button click triggers an ajax request to the server. The server then validates and sends JavaScript code back to the client. Unfortunately, the framework I am using does not allow me to incorporate jQuery a ...

Trouble with downloading files using the anchor (a) tag in React

Every time I try to click on the a tag to download the file named approved_leads.zip, I keep receiving an error message saying "failed - no file". It seems like the path is correct, so I'm not sure what is causing the issue. <a href="../../ass ...

Disappear notification with jQuery after a set amount of time

I stumbled upon this amazing script for displaying warning messages from this source: Within the script, it is configured to hide the warning message following a click event. $('.message').click(function(){ $(th ...

Setting values to an array based on the index of a specific name in JavaScript - a guide

How can I set values to an array if it has an index in the name field? Here is the sample data: [ { "column": "created_at[0]", "name": "created_at[0]", "type": "range", ...

Dropdown menu is not positioning correctly over other elements on the webpage

After researching multiple stack overflow questions and attempting various solutions, I still haven't been able to resolve my issue. Please refrain from marking this question as a duplicate. The problem I am facing is that my dropdown menu is not ap ...

Managing Chrome application authentication pop-up with Selenium Webdriver and C#

I have come across numerous discussions on this matter but none of the solutions seem to be effective. I am looking for a way to input the username and password into the chrome authentication alert using Selenium Webdriver with C# code. ...

Having trouble getting an HTML form to function with Ajax and PHP?

Seeking assistance from anyone who can lend a hand. I am delving into the complexities of Ajax, and I'm encountering issues where it seems like the script is being completely ignored or perhaps I'm just making a rookie mistake. Prior to display ...

Changing the visibility of a button based on a checkbox in JavaScript - here's how

Just starting out with JS and working on a react project. I need to toggle the visibility of a button from false to true when a checkbox is checked. Here's my code, I believe the logic is correct but it's not updating the UI. Any suggestions are ...

Switch your attention to the following input text using AngularJS

In my controller, I have an object variable called `myObject` with 3 input text fields in the user interface. I am looking for a way to automatically shift the focus to the next input field once the current one reaches its maximum length. var myObject = ...

Chrome does not support gradient, while Firefox does

When I attempt to utilize the webkit gradient tag specifically for Chrome, it fails to function altogether. On the other hand, when tested on Firefox using background:-moz-linear-gradient(#000, #888);, it operates smoothly. Despite this, applying backgrou ...