Steps for aligning equal spacing between 2 divs

Imagine a scenario where two texts are placed in two divs with equal widths. The text on the left needs to be left-aligned, while the text on the right needs to be center-aligned. However, due to this alignment, the spacing between the left edge and the left text ends up being smaller than the spacing between the right edge and the right text. How can we ensure equal spacing on both sides?

Check out this image to see the situation

Here's the CSS code:

.ll {
    position: relative;
    left:0px;
    background-color: brown;
}

.rr {
    position: relative;
    left:10px;
    background-color: green;
    float: right;
}

.left {
    background-color: red;
    color: #ffffff;
    padding: 15%;
    font-size: 20px;
    height: 100%;
}

.right {
    background-color: blue;
    color: white;
    text-align: center;
    padding: 15%;
    font-size: 20px;
    height: 100%;
}

.outside {
    border: 1px solid black;
}

And here's the HTML code:

<div class="container outside"  >
    <div class="row">
        <div class="col-6">
            <div class="left">
                <div class="ll">
                  <p>This is the LEFT text. <br> This is the LEFT text. <br> This is the LEFT text. <br> This is the LEFT text</p>
                </div>
            </div>
        </div>
        <div class="col-6">
            <div class="right">
                <div class="rr">
                    <p>This is the RIGHT text. <br> This is the RIGHT text. <br> This is the RIGHT text. <br>This is the RIGHT text. <br>
                        This is the RIGHT text. <br> This is the RIGHT text. <br> This is the RIGHT text. <br>This is the RIGHT text. <br> 
                        This is the RIGHT text.
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>

For a live example, check out this JSFiddle link

Answer №1

Note: After reviewing your question update, it seems that removing the float:right from the .rr class will resolve the issue at hand.

Initial Query

Have you tried implementing an example?

For future reference, we recommend attempting the code on your own first. If you encounter any difficulties, displaying the code you experimented with can greatly aid us in comprehending your inquiry, potentially saving time in the process.

If my understanding is correct, you aspire for a webpage akin to the visual you presented, confined within the container dimensions?

This objective can be achieved by incorporating text-align:left|center|right to the designated element. A demonstrative instance is provided below.

CSS

.container{
  max-width:900px;
  margin-left:auto;
  margin-right:auto;
}
.box{
  width:40%;
  padding:10px;
  border: 2px solid black;
}
.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;
  display: flex;
}
.space-between { 
  justify-content: space-between; 
}  
.text-center{
  text-align:center;
}

HTML

<div class="container">
  <div class="flex-container space-between">
    <div class="box">
      I will not refer to my instructor as "Hot Cakes".
  </div>
  <div class="box text-center">
      I will not swear loyalty to Bart.
    </div>
  </div>
</div>

The provided example closely mirrors the appearance captured in your photograph, all within the boundaries of the specified container width. Is this the desired outcome you were seeking?

View Live Demonstration

Explore Flexboxes Further

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

Using Tailwind CSS's width property w-11/12 actually returns a full 100% width instead of the expected 91.66

It seems that the w-11/12 class is not behaving as expected. According to the documentation, it should give a width of 91.666% but instead, it's filling up 100%. This issue only occurs with the value 11, while other values work fine. Has anyone else e ...

Stopping background content from scrolling while using position: fixed

Is there a way to prevent content from scrolling behind a fixed position element? Check out the demo here .navbar-default { background-color: #4c68f9; margin-bottom: 0; border: none; } .navbar-default.affix { background-color: #4762ed; margin ...

What is the best way to include a subscript (small letter) beneath a word using html and css bootstrap 5?

Is it possible to add a small letter (sub) below a word in HTML and CSS? I have included a screenshot for reference. I want to display "Max 100, Min 1" just like shown in the image. Here is my code: <input type="text" class="textarea" ...

Should ng-binding be avoided in CSS selectors as a general rule?

Recently, I stumbled upon this code snippet in our codebase: li.ng-binding span { font-size: 13px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; } The selector above doesn't actually apply to one of the intended 'li& ...

The picture within the div is not appearing as expected

I am facing an issue with inserting an image in a div container using CSS and HTML. The image is not displaying properly. Here is the HTML code: <div id="wrapper"> <div id="quoteContainer"> <span class="start_img"></span> </di ...

Utilizing Angular and the Kendo UI framework to customize the dimensions of a Kendo window

Is there a way to dynamically set the height and width of the kendo window based on the content of the kendo grid? Below is the code snippet for my kendo-window: <div kendo-window="Operation.OperCustWind" k-width="800" k-height="700" ...

Implementing event handling with .On() in Jquery following .Off()

I need assistance with my responsive navigation bar. I am having trouble with the jQuery code to disable hover events if the width is less than or equal to 768px and enable it for desktop screens. $(window).on('load resize', function (e) { v ...

Looking for assistance with CSS to properly align a dozen items

UPDATE: See the current layout in this JFiddle based on feedback received from others, still a few tweaks needed. In my setup, there are 12 divs housed within one container div. These 12 divs consist of 6 text components and 6 corresponding input fields. ...

The dropdown navigation bar fails to close upon being clicked

I'm currently facing an issue with the navbar in my project. The bootstrap navbar doesn't close automatically after clicking on a link. I have to move my mouse away from the navbar for it to close, which is not ideal. Additionally, I'm worki ...

What is the significance of vendor prefixes in the world of CSS3?

While I can see the rationale behind using prefixes for experimental non-official features to avoid conflicts, what is the reason for using them on shadows and similar elements? Shouldn't all vendors be implementing effects consistently according to ...

How can I modify the color of JavaFX text using CSS?

Looking to jazz up my JavaFX application with some custom CSS styling. Managed to link a stylesheet to my app using the following code: //Java code FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/path/to/fxml")); Scene sce ...

Jquery draggable droppable does not support displaying multiple divs simultaneously

I tried to implement the jquery ui draggable and droppable features to display 3 divs within a designated area. Below is the code snippet: --CSS: #content-1 { width: 200px; height: 100px; border: 1px solid red; display: none; } #content-2 { width: ...

Is it possible to incorporate Bootstrap 5 with Vue version 2 and Bootstrap-vue Components?

The project I am currently working on is built with Nuxt v2 (Vue v2, Bootstrap v4, Bootstrap-vue). It makes use of bootstrap-vue components such as: <b-navbar toggleable="md" type="dark" :sticky="true"> <b-navba ...

Update the text on the Bootstrap modal label before it is clicked

I am currently working on implementing a Bootstrap modal with a label control. The modal is triggered by clicking a button, and I am facing an issue where I need to change the text of the label before the modal launches. However, the text that is supposed ...

Is it frowned upon or considered incorrect to achieve a horizontally centered page by adjusting the CSS properties of the html tag?

Is it considered wrong or frowned upon to center a webpage horizontally by adjusting CSS properties of the HTML tag? Sample CSS code: <style type="text/css"> html { width: 1200px; margin: 0px auto; background-color: ...

The footer on my page seems to be having trouble connecting with the div section above it, causing it to abruptly halt in the middle

After spending a considerable amount of time, I managed to make my footer responsive by sticking it to the bottom of the page regardless of which page you are on. The code that achieved this is as follows: position: absolute; bottom: 0; However, the issu ...

Enhancing Application Views in ExtJS Classic 7.3.0 using .scss Style Sheets

Referencing the guidelines provided in this resource for theming: In order to create CSS rules specific to an application view, you need to generate an .scss file within the same directory and with a matching base name as the view. For instance, if you w ...

How can I prevent CSS styles from affecting all the tables on my website?

One issue I'm facing is that the CSS code intended for one table is affecting all the other tables on my website. Here is an example of the CSS code: tr:last-child td:last-child { border-bottom-right-radius:3px; } /*effects map*/ td { background: ...

Discovering the root cause of why a particular CSS style is not being implemented correctly

Currently, I am in the process of developing a secondary theme for one of my websites. It's going to be a dark theme. I'm facing an issue where a specific CSS style is not being applied to a particular element, even though it works perfectly fine ...

Fan Animation in CSS

I have three unique images that I would like to animate in a fan-like manner consecutively. I prefer not to merge the images in Photoshop, as I want them to be displayed one after the other. Here is the code snippet (dummy images are used): .bannerimg ...