Arranging Elements Individually Using Bootstrap 4 in a Row or Column

Utilizing Bootstrap 4, I am designing a row with two items placed in a column. The first item should always be aligned to the left of the row, while the second item is centered within the row. I have successfully achieved this layout using custom CSS. Is it possible to accomplish the same result solely using Bootstrap without additional CSS?

Below is the CSS code I have used:

.float_left {
    float: left;
}

.float_center {
    float: right;
    position: relative;
    left: -50%;
    text-align: left;
}

.float_center > .child {
    position: relative;
    left: 50%;
}

Here is the corresponding HTML:

<div class="row" >
    <div class="col-12" style="z-index:5000;">       

        <span class="float_left">Left</span>

        <div class="float_center">
            <span class="child">Center</span>                        
        </div>
    </div>
</div>

Answer №1

  1. Using display:flex; ensures that the items will be displayed in a single row.
  2. If you set the width to equal sizes, such as 50%, and align the text to the left, it will automatically center the content without any additional code needed.
  3. Flexbox is great for creating layouts, so there's no need to worry about responsiveness as flex will take care of that too.

.align {
  display: flex;
  border: 1px solid red;
  width: 100%;
}

.float_left,
.float_center {
  width: 50%;
  text-align: left;
}
<div class="row">
  <div class="col-12 align" style="z-index:5000;">

    <span class="float_left">Left</span>

    <div class="float_center">
      <span class="child">Center</span>
    </div>
  </div>
</div>

Answer №2

Have you considered using col? It seems like it would be effective.

<div class="row">
        <div class="col-12" style="z-index:5000;">       

            <div class="row">
                <span class="col">Left</span>

                <div class="col">
                    <span class="child">Center</span>                        
                </div>
            </div>
        </div.
    </div>

If a fixed width is needed for the left side, consider implementing custom widths.

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

Implementing a Bootstrap card component in a React application

I've been struggling with incorporating Bootstrap into my React project. Initially, I set up bootstrap4 but encountered layout issues. I then tried using react-bootstrap but faced the same problem where the card body, title, and button were all appear ...

Using varied colors to style list items

Is there a way to apply three different colors to my list items? What is the best method for achieving this? This is what I have in my code: li { width: 33.333%; float: left; padding: 15px; list-style: none; } .light { background-color: #0 ...

Can you explain the purpose of using href="#" in web development?

I've noticed that numerous websites use links that have href="#". Can you explain what this means and how it is typically used? ...

Is there a way to enlarge an image to fullscreen when clicked on?

I'm working on a table that contains images and I want to implement a feature where clicking on an image will make it fullscreen, and then clicking on the fullscreen image will return it to the table. I am developing this using PhoneGap for mobile d ...

Minify your Angular code and include background images through URLs specifically for production mode

Trying to create a gradient image background in CSS using Angular 6 with the CLI template. Everything looks great in dev mode, but when I switch to the production version (ng build "--prod"), the CSS code becomes invalid. Here is the SCSS file: .home-con ...

What is the best way to deactivate div elements once an overlay has been applied to them?

My goal is to place an overlay on my form to prevent users from accessing the content. Even though I have added an overlay, users can still interact with input fields. How can I prevent that? .overlay { background: rgba(0, 0, 0, .75); text-align: ce ...

Is there an alternative method to including a PHP file from a remote server other than using the "<?php include(); ?>" syntax?

I have developed a PHP script that retrieves information from a MySQL database and I am looking to integrate this script (which contains extracted content from the database) onto various remote servers. These clients have websites built with Joomla/WordPre ...

Extracting specific text from HTML tags using Python's BeautifulSoup

I'm trying to extract specific tags from two different sections of text using the BeautifulSoup library in Python. Here's what I've attempted so far: g = soup.find_all("dtposted") for tag in g: print(tag) <dtposted>2020<trnamt& ...

Tips for displaying play and pause text when hovering

In my demo application, I have successfully created a Play and Pause icon. However, there is an additional requirement - I need to display the text PLAY and PAUSE when hovering. Currently, I am encountering two issues: The icon jumps when hovering over t ...

Align Bootstrap 4 div.card horizontally in the center

I have a website where I am displaying articles from a database using Bootstrap 4. I want the card blocks (div.card) to be horizontally centered no matter how many there are, with a maximum of 3 blocks per row. I have tried various methods but haven't ...

Is there a way to check the existence of an email in the database without having to refresh the PHP page?

Currently, I am using the following method to validate my inputs: <form method="post"> <label>Email</label> <input type="email" name="user_email"> <input type="submit" name="reg"> </form> if(isset($_POST['reg' ...

Is there a way to verify if the overflow of an element with a width of 100% has occurred?

Here is the structure I am working with: <div class="card"> <div class="container"> <slot /> </div> </div> The Card element has a fixed width of 33rem. The container within it spans 100% of ...

Add color to the cells within the table

I need help with dynamically adding colors to my table based on the results. If the result is 'UnSuccessfull', the color should be 'red'. If the result is 'Successful', the color should be 'green'. The challenge I a ...

Steps for positioning one div below another:1. Set the position property

Indeed, I am aware that this question has been asked numerous times in the past. Despite trying other solutions, none seem to resolve my issue. My objective is to have the "register" div slide down beneath the "container" div, rather than appearing next t ...

Reviewing code for a simple form and box using HTML5 and CSS3

I have developed a compact form as part of a larger webpage, proceeding step by step according to the specified requirements. I am wondering if there could have been a more efficient way to code this. Perhaps streamlining the code or utilizing different c ...

The right floating behavior with <li> elements seems to be malfunctioning

I am currently dealing with an issue in my code where it works perfectly in Firefox and IE 8, but in IE 7 the second list item is displaying with some extra space at the top instead of being on the same line. <LI style="PADDING-LEFT: 20px"> ...

CSS magic: Text animation letter by letter

I have a <div> with text. <div> to be revealed on the page one character at a time:</p> <div>, the animation should stop and display the full text instantly.</p> In summary, I aim to replicate an effect commonly seen in Jap ...

Modify the contents of the 'data-content' area in the popover

Looking for a solution where I can update only a portion of the data-content within a popover. Here is an example code snippet: <div class="popover-wrapper"> <i class="glyphicon glyphicon-question-sign hover_content" ...

Neglecting to include an external CSS file within a .aspx content page in an ASP.NET WebForms application

I've been facing some challenges while trying to incorporate an external CSS file into the content pages of my asp.net WebForms application. The content pages have a master page (Site.Master) which includes the following code in the head section: < ...

Creating evenly spaced columns within a structure

Is there a way to create 3 equal columns in HTML5 without using tables? I'm having trouble achieving the desired result: https://i.sstatic.net/AJIA3.png The issue is that one of the columns doesn't look like the other two, even though they all ...