What is the best way to align two blocks and a span with fixed widths horizontally using CSS?

Is it possible to have a span with a static width of 20px (like col-2) placed between two blocks with content in Bootstrap, where the blocks split the rest of the available space?

Here is an example code snippet: https://jsfiddle.net/Alexik/krexqp5m/1

Condensed code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="row">
  <div class="left-player d-inline-block col-5">
    <div class="input-group mb-2">
      <select class="form-control"></select>
    </div>
    <div class="input-group mb-2">
      <select class="form-control w-25"></select>
      <select class="form-control"></select>
      <span class="input-group-text">
        <input type="checkbox">
      </span>
    </div>
  </div>

  <span class="d-inline-block align-top col-2 text-center">VS</span>

  <div class="right-player d-inline-block col-5">
    <div class="input-group mb-2">
      <select class="form-control"></select>
    </div>
    <div class="input-group mb-2">
      <select class="form-control w-25"></select>
      <select class="form-control"></select>
      <span class="input-group-text">
        <input type="checkbox">
      </span>
    </div>
  </div>
</div>

Answer №1

you can utilize the flex property in this section

steps

  1. place the tag inside with both divs and span set to display: flex; I used body in my example
  2. assign flex-grow to each of the divs
  3. specify a width for your span

css:

    body
    {
        display: flex;
    }
    div
    {
        flex-grow: 100;
        background-color: rgb(128, 122, 118);
    }
    span
    {
        width: 20px;
    }

html:

    <div>
        this is div one
    </div>
    <span>
        vs
    </span>
    <div>
        this is div two
    </div>

output

I suspect that using bootstrap classes might not be effective here since their grid is divided into 12 segments.

Answer №2

Utilizing bootstrap, it seems difficult to set an exact size for a span element. However, CSS flex provides the flexibility to easily achieve this customization.

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

Is there a way to use a media query on a div element to check for the presence of a scroll bar?

A div has been styled with overflow-y: auto, triggering the appearance of a vertical scroll bar when the content exceeds the height of the div. This causes the content to shift horizontally to accommodate the scroll bar, resulting in misalignment with the ...

Embed the WordPress header file outside of the WordPress platform

Recently diving into the world of WordPress, I am eager to integrate the WordPress header file into my PHP file in order to display the identical header as seen on the WordPress site. I am exploring potential methods to achieve this as I work on creating ...

Are there any methods to achieve smoother font icons on Firefox?

When it comes to using icons on different browsers, I've noticed an issue. Icons appear sharp on Google Chrome and Opera, but when viewed on Firefox they tend to look blurry if the font-size is less than 20px. Strangely enough, once the font size reac ...

Arrange array with objects in order of most recent date

I am in the process of developing a chat application where all contacts are stored as objects in one array: var contacts = [{name: "Ruud", age: 20},{name: "Elke", age: 17}]; Next, I have the chat messages for each contact saved in an array of objects: v ...

Issue with website header disappearing

I'm currently struggling with an issue - I can't seem to pinpoint the problem. The header of a website template is functioning perfectly in 1280*800 resolution, but it's breaking on larger monitors (1900*1440). The header consists of three d ...

When consecutive DOM elements are hidden, a message saying "Hiding N elements" will be displayed

Provided a set of elements (number unknown) where some elements should remain hidden: <div id="root"> <div> 1</div> <div class="hide"> 2</div> <div class="hide"> 3</div> <div class="hide"&g ...

.css files standing their ground against modifications

Currently, I'm utilizing the WebStorm IDE to work on my React project. My goal is to make modifications to the app.css files in order to update the design. However, each time I attempt to build or run the project, it dismisses all of the changes I&apo ...

I'm having trouble getting my Django for-loop to show the items

Having trouble displaying all the songs on my music streaming website homepage using a carousel. Even though I have around 10 songs in my database, nothing is showing up. How can I fix this issue? This is the HTML code I am using: <div id="All-song ...

Sending emails to multiple recipients with different content using Nodemailer

I have been working on a method to send emails to multiple recipients while also passing the user attribute, which contains the name of the recipient, to the html template. (I AM UTILIZING NODEMAILER as a nodejs module) My current code looks like this: S ...

Encountering an error while attempting to load the jQuery script: TypeError - $.fn.appear.run is not a

I have included an animation script for CSS in my markup, but I am encountering the following error: TypeError: $.fn.appear.run is not a function Does anyone know why this is happening and how I can resolve it? /* * CSS3 Animate it * Copyright (c) 2 ...

Having trouble locating elements with Selenium in Java?

I've been struggling to locate a particular WebElement using Selenium's API. I attempted to use a wildcard to capture all elements on the page and then iterated through them, but I'm still unable to locate the desired element. Could it possi ...

Can you explain the function of mdLiveAnnouncer in Angular Material and how it operates?

Could someone provide an explanation of $mdLiveAnnouncer using this code snippet? module.controller('AppCtrl', function($mdLiveAnnouncer) { // Making a basic announcement (Polite Mode) $mdLiveAnnouncer.announce('Hey Google'); // ...

A collection of items displayed in an unordered format across two columns

I need help creating a list that displays in two columns. One column for odd numbers, the other for even numbers. Here's an example of what I'm trying to achieve: +----------------------------------------------------+ | col- ...

Guide on utilizing font-awesome icons stored in node-modules

After successfully installing font-awesome 4.0.3 icons through the npm install command, How can I incorporate them into an HTML file from the node-modules directory? If edits need to be made to the less file, do they have to be done within the node-modul ...

Expanding and collapsing multiple rows within a Bootstrap grid

Seeking advice on Bootstrap and its implementation of columns and rows. Currently facing a cascading effect where I have managers, followed by employees, and then employee family members. The challenge lies in my limited understanding of how Bootstrap uti ...

Center a vertically aligned element following a heading, with the content dynamically generated and enclosed in a fixed container

My mind is racing with this problem and I'm not sure if it's solvable, but before throwing in the towel, I thought I'd seek help from the Internet Gods. Here's a visual representation of what I'm aiming for: I want the text to al ...

The datepicker feature mysteriously vanishes when using Safari browser

When I utilize the jquery ui datepicker (range) and open my datepicker, if I scroll down the page, the calendar disappears. This issue seems to only occur on Safari browsers with mobile devices. Has anyone else experienced this problem? Would someone be ...

Preventing duplicate Google indexing with .htaccess

I have a website that utilizes a RewriteRule in the root directory to direct queries in this format: http://domain.com/foo/parameter to http://domain.com/index.php?args=parameter Visitors only see the clean URL and everything works smoothly. However, ...

Whenever I try to update my list of products, I encounter an error message stating that the property 'title' cannot be read because it is null

I am encountering an issue with editing data stored in the database. When attempting to edit the data, it is not displaying correctly and I am receiving a "cannot read property" error. HTML admin-products.component.html <p> <a routerLink="/ad ...

Employing negative margin to connect div1 to the left side of div2

Is there a way to attach a dismiss button to the left of a contact in a sidebar? I am trying to achieve a layout similar to the one shown in this image: https://i.sstatic.net/jJE3h.png I attempted using margin-left: -50px; or left: -50px;, but the dismiss ...