Tips for positioning text on the left and right sides of a div in HTML styling

I am struggling with positioning two pieces of text within a div. Despite having some styling already in place, the text is currently displaying one after the other on the left-hand side. I want to position one piece of text to the left and another to the right for better readability.

In my component code, I have tried to allocate the left-text class to the left side of the text-div class and the right-text to the right side. However, it's not working as expected. The text is appearing like this ---> text1text2

Here is my updated component code:

return (
        <div className="container-one">
            <div className="container-two">
                <Comp/> 
            </div>
            <div className="text-div">
                <span className="left-text">{text1}</span>
                <span className="right-text">{text2}</span>
            </div>
        </div>        
    )

Below you can find the current CSS styles applied:

.left-text{
    float: left;
    text-align: left;
}

.right-text {
    float: right;
    text-align: right;
}

.text-div {
    display: flex;
    align-items: center;
}

.container-two {
    width: 100%;
    border-radius: 9px;
    margin-bottom: 9px;
}

.container-one {

    width: 100%;
    font-size: 12px;
    flex: 0 0 auto;
    
    display: flex;
    
    flex-direction: column;
    
    position: relative;

}

Answer №1

To create the desired effect, simply include justify-content: space-between; within the .text-div section of your CSS code

.text-div {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

Answer №2

If you want to create a layout with some spacing between elements in your .text-div class, simply include the property justify-content: space-between;.

.text-div {
    display: flex;
    align-items: center;
    justify-content: space-between; /*Remember to add this line.*/
}

Additionally, I recommend checking out this helpful resource on flexbox that I found useful during my learning journey.

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

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

PHP Administrator Access

When a user logs in as an admin on my website, I want certain options to be available. My concern is ensuring the security of this admin account. Currently, after the login process is authenticated, I set $_SESSION['status'] = 'authorized&ap ...

Combining color and typography classes using Tailwind merge is currently not supported

In my custom styling setup, I have created a custom color class called text-green (colors) and a custom typography class called text-card-highlight (utilities), which includes font size and weight attributes. However, when using tailwind-merge, only one of ...

Issues with displaying PNG background images in older versions of IE while using HTML5?

Below is the HTML code that I am working with: <section class="first-content-top"> <img src="images/img-diner.png" /> <h1>Menu</h1> </section> <section class="first-content-middle"> <article class="m ...

Error handling in Mongoose callback functions

Currently, I am delving into nodejs, express and mongoose. A question has arisen in my mind regarding the findOne function used to fetch a document from the database. Typically, it is utilized like this: Product.findOne({_id: req.params.id},function(erro ...

Concern raised about the challenge of removing an element from an array and its potential

When attempting to remove an element from an array without altering the state, I typically use the following code snippet: const tempArray = [ ...originalArray ]; tempArray.splice(index, 1); setOriginalArray(tempArray); After some experimentation, I deci ...

What is causing the question mark symbol to appear at the beginning of my ajax response?

Below is my JavaScript code: $('#tags').select2({ tags: true, tokenSeparators: [','], createSearchChoice: function (term) { return { id: $.trim(term), text: $.trim(term) + ' (new tag)&ap ...

Unlocking the power of keys in manipulating JSONP objects

i am uncertain about the accuracy of my title, as i am unsure how to label the task at hand... "modifiers":{"agility":{"type":"attribute","displayname":"agi","value":46}} forms a part of a jsonp callback that is received from this source. i am attempting ...

What is the best React component to utilize with specific parameters?

This is my MainLayout Component: export const MainLayout = ({header, content, footer}) =>( <div> <header> {header} </header> <main> <Paper style={contentStyle} zDepth={1}> {content} ...

What is the best way to make a vertical line using the CSS code provided in the link?

Check out this cool horizontal line design I found on stackoverflow: Click here for CSS code to create the line I really like the look of the line. Here's how I implemented it on my website: hr.fancy-line { border: 0; height: 5px; } hr ...

`validate.js verifying the elements within an array`

One of the challenges I'm facing in my JavaScript project is dealing with objects that have two array properties included. As part of my development process, I've decided to utilize the resources provided by the validate.js library. To illustrat ...

Is there a way to efficiently clear the Express session for all users without the need to restart the application?

During my development of REST services using the nodejs express framework, I encountered an issue with storing user-specific data in sessions. I utilized the user's ID as a key to identify the user's data. The following code snippet demonstrates ...

Generate a div element dynamically when an option is selected using AngularJS

I'm having trouble dynamically creating div elements based on the selected option value, but for some reason ng-repeat isn't working as expected. Can you help me figure out what I'm missing? Here's the HTML snippet I'm using - &l ...

Struggling to navigate the use of Firebase v3 for hosting my React demo

I need assistance with hosting React apps on Firebase. I recently followed the instructions provided in the new v3 documentation on Firebase.com, but I am unsure about which files/assets should be placed in my public directory. The documentation seemed a b ...

Modifying the color of a non-active tab - Material UI Tabs

Is there a way to customize the color of inactive tabs in Material UI tabs? I have noticed that they currently appear black, as shown in the screenshot here: screenshot Thank you! ...

Problem with the $http module in Angular 1.2

Recently, I started incorporating Angular 1.2.0 into my development application and encountered an issue with a particular function not working as expected: var myItems = angular.model('myItems', []); myItems.controller('itemsController&ap ...

The appearance of a printed webpage does not match what is shown in Google Chrome's Print Preview feature

I have encountered a strange issue that has me stumped. I need the webpage in my current project to be completely printable, but I'm facing difficulties. While the signature field and note field (with the text "erererer") display perfectly in Google C ...

Issue with second button in Angular Onclick() not been resolved

I'm experiencing an issue with the onClick() methods in my code. There are two onClick() methods present on the UI, but when I click on the second one, it does not call the method while the first one does. I am struggling to figure out why this is hap ...

unable to send array in cookie through express isn't functioning

Currently, I am in the midst of a project that requires me to provide the user with an array. To achieve this, I have been attempting to utilize the res.cookie() function. However, each time I try to pass an array as cookie data, the browser interprets it ...

Configuring Vue.js watchers inside a for loop

Exploring the dynamic addition of watchers in Vue.js. The discrepancy between what is desired and what actually happens is demonstrated below in the commented section. As a casual coder, I believe my issue lies more in grasping JavaScript basics rather t ...

Retrieve information filtered based on the query parameter

Utilizing react hooks for dynamic data rendering, I am focusing on two main tasks: a. Extracting URL parameters from the component's history props. b. Retrieving state data from the component's history props, which provides an array of objects ...