Position two elements next to each other in a fluid/responsive manner with an unspecified width

I have recently been assigned a React project for my Full-Stack position at work.

Within a wrapper div, there are 2 nested divs.

Here's the breakdown of these divs:

  1. Left Div - Contains text within a span, with ellipsis and hidden overflow, allowing the parent div width to adjust based on content.
  2. Right Div - Displays a Sorting Icon that should be aligned to the right of the left div and take up the remaining space of the parent div, while also staying next to the header text [Zoom friendly].

Desired layout: https://i.sstatic.net/2jP51.png

Current layout: https://i.sstatic.net/MLqzF.jpg

HTML structure:

return (
    <>
        <div className={classes.headerWithSort}>
            <span>{col.label}</span>
            {canSort ? (
                <div>{sortIcon}</div>
            ) : null}
        </div>
    </>
);

Corresponding JSX/CSS:

headerWithSort: {
    position: 'relative',
    border: '1px dashed black',
    height: 'inherit',
    width: 'inherit',
    '& > span': {
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap',
        lineHeight: '3.29rem',
        border: '1px dashed green',
        float: 'left'
    },
    '& > div': {
        border: '1px dashed red',   
        overflow: 'hidden'
    },
    '& > *': {
        height: 'inherit'
    }
},

[Edit] - Another example of desired layout: https://i.sstatic.net/uEJGg.png

I've been struggling with this setup for a while now, any assistance would be greatly appreciated. Thank you!

Answer №1

To enhance your project, I recommend incorporating Bootstrap Content Delivery Networks (CDN) in the following manner:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
</script>

<!-- Popper JS -->
<script 
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"> 
</script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"> 
</script>

Afterward, you can establish 2 columns with differing sizes on your webpage and input your content accordingly:

<div class="container">
 <div class="row">
   <div class="col-sm-5">
     <h3>Elipses text</h3>
     <p>Lorem ipsum dolor..</p>
   </div>
   <div class="col-sm-7">
     <h3>icon</h3>
     <img/>
   </div>
 </div>
</div>

Remember, Bootstrap columns are always divided into 12 parts, so make sure they add up to 12 for proper alignment. If you desire equal-sized columns taking up half of the page, utilize "col-sm-6" for both. This method is invaluable for responsive web design, especially when combined with Media queries.

Mastering Bootstrap is an excellent way to delve into efficient and adaptable web development practices.

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

Manipulating the size of the Chrome viewport manually yields varying outcomes compared to resizing within the browser using the "Inspect" tool

I'm currently working on developing a responsive custom theme for Wordpress. I have it hosted locally using WAMP and employing different tools to ensure it is mobile-friendly. However, I am encountering inconsistencies in the results, especially since ...

Preserving information from a disconnected Checkbox

As I work on developing my app, I've encountered a slight hiccup in the process. Currently, I'm faced with the challenge of preserving data generated by if statements for a checkbox. While I have successfully achieved this for a radio button by s ...

Experiencing the error message "Unable to access property 'innerHTML' of null" despite initializing the corresponding ID

After doing some research, I discovered that this issue usually arises when the specific div is not loaded yet or simply does not exist. My code is set to loop continuously, ensuring that even if it wasn't fully loaded the first time, it will be by th ...

I am working on customizing my WordPress website using three.js to add a background with a wireframe effect. However, I am facing difficulties in placing a sphere at the end of each line

I have a beautiful turquoise diamond and I want to incorporate a directional camera view in the background of a WordPress section. However, I am unsure how to achieve this. The issue I'm facing is that I created a wireframe over the diamond, but when ...

The appearance of HTML in JSP and CSS output in a Spring application is different from the local environment

For my web application's landing page, I created the design using HTML and CSS. Typically, I first design it on scratchpad.io before implementing it into my STS IDE. However, when I run the application, the output of the page appears different from th ...

Adding Elements to an Array with JavaScript

I am currently working on simulating a mailbox using Materialize for the design. In my collection view, I want to add cells dynamically, but I need help with appending HTML using JavaScript. <div class="row" id="mailBox"> <div class=" ...

Encountered an error while attempting to minify code during the npm run build

After completing my react application using create-react-app , I encountered an issue when trying to build it with npm-build. While there were no problems running it locally with npm start, I faced an error during minification of the code. I attempted ...

Tips for managing accordion events using a button press

I found a script online that I want to modify. Specifically, I am looking to create a button that will control the accordion event by closing the current div and opening the next one. <button> Click me to open next</button> inside each div in ...

Save user input in a textarea to an HTML file without the need for a database in

I am working on an ASP.NET Core project where I need to incorporate a 'notes' section on the home page that allows any user to add notes. The current implementation includes the following HTML elements: <p id="noteSection"></p> < ...

What is the process for setting up a subdomain in React?

As I work on developing a website with sections for customers and companies, I am considering creating a separate subdomain specifically for the company dashboard. Much like Stripe or Fauna, I want to give them their own space under dashboard.myapp.com. Wh ...

Ways to Achieve the Following with JavaScript, Cascading Style Sheets, and Hypertext

Can someone help me convert this image into HTML/CSS code? I'm completely lost on how to do this and don't even know where to start searching for answers. Any assistance would be greatly appreciated. Thank you in advance. ...

Arranging divs of varying heights in a grid formation

I am working on a website layout that needs to look like the image provided: The red section represents the desktop version, while the yellow section represents the mobile version. I can easily switch between the two layouts using media queries. My chall ...

Allow only specific inner divs to dictate the width of the outer div

I'm working with the following HTML structure: <div id="container"> <div id="block1"> <img src="someimage/path" /> </div> <div id="block2"> Some Text </div> <div id="block3"&g ...

What is the best way to send custom data attribute props to child components in React?

Essentially, I am working with 3 custom attributes called data-pageName, data-defaultOption, and data-options. The issue I am facing is that when I pass them into my child component, I encounter an unexpected token error due to the following code snippet: ...

Exploring the CSS positioning with the power of JQuery

How can I identify if a specific PNG file is placed next to another PNG file on a webpage, and trigger an alert if they are? The issue I'm facing is that the alert pops up as soon as the webpage loads. Here's the code I'm using for the PNG ...

Universal loading screen across all components

I am currently implementing a loading screen for this component in conjunction with the fetch method. My concern is whether I will need to replicate the same loading logic used in the example for every component that utilizes the fetch() method, or if the ...

Navigational Arrows within a JQuery Image Carousel

I've successfully developed an image slider using a combination of HTML, CSS, and JS (Jquery). The slider consists of 5 images that users can navigate between using arrow buttons. Everything is functioning correctly so far, but I'm encountering a ...

Encountering difficulties accessing XML file on server via anchor tag

I have an XML file on the server that I am attempting to open in a browser when the user clicks on a link. Below is how I have set up the link, but it is not opening the file: Code: <a title="View XML" href="file://///90.0.0.15/docmgmtandpub/PublishD ...

Strange and unexpected dots appearing in my dynamic timeline

After finding a responsive timeline on codepen, I decided to use it for my website because creating one from scratch seemed like too much effort. I made some modifications to fit my needs, but there's one irritating issue that I can't seem to get ...

What is the method to activate a function whenever a particular state is

I'm searching for a solution to associate a specific function with a change in a particular state. Here is the code I have written: export type MoviesAppState = { search: string; searchBy:string; startDate: number; endDate: number; } ...