What is the best way to ensure a variable-width column stays perfectly centered within a three-column layout?

I need help with aligning text in a toolbar-like control. The left side contains variable-size text, the center has a small block of text, and the right side also has text.

My goal is to always have the center text centered without knowing its width in advance. The left and right sides should expand to fill available space and then wrap if needed.

I've attempted various methods but none seem to work as intended. Here's what I've tried:

 

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<br/>
not centered:
<div class="d-flex justify-content-between">
   <div class="border">
  left left left left left left left left left left left left
   </div>
   <div class="border">
  center
   </div>
   <div class="border">
  right
   </div>
</div>
<br/>
not on the same line:
<div class="d-flex flex-column">
   <div class="border align-self-start">
  left left left left left left left left left left left left
   </div>
   <div class="border align-self-center">
  center
   </div>
   <div class="border align-self-end">
  right
   </div>
</div>
<br/>
left does not fill space up to the center content:
<div class="container row">
   <div class="col border">
  left left left left left left left left left left left left
   </div>
   <div class="col border text-center">
  center
   </div>
   <div class="col border text-right">
  right
   </div>
</div>

Feel free to run the snippet for a better understanding of my issue. Any suggestions on how to properly center the text while accommodating variable widths would be greatly appreciated!

Answer №1

Text of varying sizes appears on the left side.

In the middle, there is a compact block of text that occupies the necessary space.

To the right, additional text can be found.

The content on the left and right should expand to fill the available area before wrapping around.

Does this meet your expectations?

Utilize the col-auto class to utilize all available space. You can also specify the width using classes like col-4 or col-3 if you want the left side to have a consistent width and the text to wrap accordingly.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="row">
   <div class="border col">
  continuous text on the left
   </div>
   <div class="border col-auto">
  centralized
   </div>
   <div class="border col">
  precise
   </div>
</div>

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

Insert the element both before and after it is referenced

There was a php script I was working on that involved calling a function. For example, here is the script: <div class="main-info"> <div class="screenshot"> </div> </div> <div class="screenshot-later" ...

A cool CSS technique for adding a subtle inset box shadow to images with the added bonus of centering both vertically and

After discovering a useful trick here to add an inset box-shadow on the images in my gallery, I encountered three challenges: Difficulty centering the image and surrounding anchor vertically and horizontally in their container Unable to limit the image h ...

Deactivate the button when the length is less than x

Hey there! I'm new to JavaScript and I'm working on replicating a specific webpage. On this page, there's a button that should be disabled if the login form doesn't have at least 11 characters for the user input and 8 characters for the ...

Issue with visibility of Bootstrap modal title

The title in the modal isn't visible. Even when I highlight it with a mouse, it still doesn't show up. I attempted to add modal-content color: #000, but unfortunately, it had no effect. As of 01/11/16 1:28PM CST, none of the responses and answe ...

Troubleshooting issue with changing class based on input values

It appears that there is an issue with the functionality when switching values on page load. Initially, I was able to make it work for a single switch, but now that there are multiple switches on the page, toggling affects all of them. How can I modify it ...

Is it possible to integrate Vue.js with Laravel and bootstrap in a web development project?

In order to build a basic website equipped with a forum feature, my plan involves integrating Vue JS with Laravel and Bootstrap. I am confident in the necessity of Vue JS for this project, but I am open to alternative options for Laravel and Bootstrap. I ...

Angular 4: Troubleshooting Navigation Bar Dropdown Dysfunction

As a novice starting out with Angular 4, I decided to work on creating some simple components as a part of my learning journey. One of the components I focused on was implementing a bootstrap navbar. Below is the code for the Navbar: <nav class="na ...

What is the reason for receiving 'undefined' from await page.Evaluate() function call?

My attempt at creating a deploybot using nodejs is encountering an issue when trying to access the environments page, as it's unable to locate the button. The code snippet in question is as follows: //wait until element with unique id contain ...

Issues with the Bootstrap Grid system

I seem to be facing an issue with my Bootstrap Grid. Shouldn't it be filling up the entire row? View image of potential incorrect behavior <div class="container min-vh-100 pt-5"> <h5 class="text-white mt-2">{{event?.tea ...

Display additional tiles within a compact container

I'm attempting to replicate the user interface used by foursquare! Positioning the map slightly off center like they have . I've figured out how to do one part but struggling with the second part. Initially, I loaded the map in a small div (t ...

"Dilemma with Displaying a 3-Digit Number in DaisyUI Using Next.Js Countdown Component

Hey there, I'm encountering an issue with the countdown component on my Next.js website using daisyUI. When the number of days exceeds 99, it's not rendering correctly as shown below: https://i.sstatic.net/cWR2tSEg.png https://i.sstatic.net/V0Iv ...

Improper Placement of Bootstrap 5 Modal

I seem to be facing an unexpected issue where the Bootstrap 5 Modal and other components are displaying inside the sidebar menu instead of the main content area. Has anyone encountered this problem before? How can it be resolved? Here is a test example: ...

Implementing a feature in a Django blog to showcase the most recent post on every page when using a

Currently facing an issue with displaying the latest posts on my Django blog. Despite implementing a paginator, I am unable to showcase the latest posts on every page. views.py def post_list(request): post_list = Post.objects.all() page = request ...

What steps should I take to ensure I receive a response after submitting a form to a designated API?

I developed an API that retrieves data and stores it in a MongoDB database. const userDB = require('./model/user') app.post ('/signup', function (req, res){ userDB.find({username: req.body.username}). then (result=>{ ...

Tips for capitalizing the first letter of a directory

I want to automatically convert all directories in the URI to lowercase if the user types them in uppercase. For example, https://example.com/hOmE should be converted to https://example.com/home. ...

Disable the click event using jQuery

$("button").click(function (){ $("<button>Start</button>).appendTo('main'); }); The code above introduces a functionality where clicking a button generates another button dynamically. However, each subsequent click kee ...

Increasing or setting a minimum value for a <input type="number"> compared to a specific number

I'm working with a form that looks like this: <input type="text" id="theName"> <input type="number" id="theNumber"> <input type="button" id="submitForm"> I need to implement validation using AngularJs when the submit button is clic ...

Transforming fonts into various web-compatible font formats

This morning, I delved into the fascinating world of fonts as I am in need of a specific font for my CSS project. It appears to be quite complex to rely on others for correct font types, so I started exploring methods to convert fonts from one type to ano ...

Bootstrap Overlapping Problem: Find a Solution

Currently, I am in the process of learning how to create a responsive website using bootstrap. Although I have been making progress, I realize that my code may not be as clean as it could be. However, my current concern revolves around overlaying an image ...

Introducing a new left overlay panel popup feature using jQuery Mobile

I'm currently developing a mobile app and I'm having trouble getting a popup to launch on the left overlay panel when clicked on "Sign out". I can't figure out where I'm going wrong. Can someone please provide some suggestions? Thank yo ...