Tips for aligning numerous rows in a single column using Bootstrap

I have a col div with 3 row divs that I am trying to center within the col div. Currently, they are aligned to the left side of the col div as shown in the image. I am struggling to figure out how to place them in the center of the col div.

https://i.sstatic.net/H5ld6.png

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>

<div class="col text-center">
  <div class="row">
    <div id="tantargyselectdiv" class="col-sm-5">
      <select name="tantargyselect" id="tantargyselect">
      </select>
    </div>
    <div class="col-sm-5 text-center">
      <div class="form-group">
        <button type="submit" class="btn btn-primary">Mehet</button>
      </div>
    </div>
  </div>
  <div class="row">
    <div id="tanarselectdiv" class="col-sm-5">
      <select name="tanarselect" id="tanarselect">
      </select>
    </div>
    <div class="col-sm-5 text-center">
      <div class="form-group">
        <button type="submit" class="btn btn-primary">Mehet</button>
      </div>
    </div>
  </div>
  <div class="row">
    <form action="{{URL::to('statisztikaBetoltFelev')}}" method="post">
      <input type="hidden" name="_token" value="{!! csrf_token() !!}">
      <div id="felevselectdiv" class="col-sm-5 text-center">
        <select name="felevselect" id="felevselect">
        </select>
      </div>
      <div class="col-sm-5 text-center">
        <div class="form-group">
          <button type="submit" class="btn btn-primary">Mehet</button>
        </div>
      </div>
    </form>
  </div>
</div>

As an amateur in web development, I understand that this may not meet professional standards. If you have any suggestions on improving the styling, I would greatly appreciate your help.

Answer №1

Many users mentioned the use of justify-content-center, but no one provided a complete solution, so I decided to share my approach.

Take a look at the code snippet below for a clear explanation:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>

<div class="col text-center">
  <div class="row justify-content-center">
    <div id="tantargyselectdiv" class="col-sm-5">
      <select name="tantargyselect" id="tantargyselect">
      </select>
    </div>
    <div class="col-sm-5 text-center">
      <div class="form-group">
        <button type="submit" class="btn btn-primary">Mehet</button>
      </div>
    </div>
  </div>
  <div class="row justify-content-center">
    <div id="tanarselectdiv" class="col-sm-5">
      <select name="tanarselect" id="tanarselect">
      </select>
    </div>
    <div class="col-sm-5 text-center">
      <div class="form-group">
        <button type="submit" class="btn btn-primary">Mehet</button>
      </div>
    </div>
  </div>
  <div class="row justify-content-center">
    <form action="{{URL::to('statisztikaBetoltFelev')}}" method="post">
      <input type="hidden" name="_token" value="{!! csrf_token() !!}">
      <div id="felevselectdiv" class="col-sm-5 text-center">
        <select name="felevselect" id="felevselect">
        </select>
      </div>
      <div class="col-sm-5 text-center">
        <div class="form-group">
          <button type="submit" class="btn btn-primary">Mehet</button>
        </div>
      </div>
    </form>
  </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, delete, and modify rows within the table

I'm struggling with a JavaScript issue and could use some help. How can I add a new row for all columns with the same properties as the old rows, including a "remove" button for the new row? Is there a way to prevent editing cells that contain b ...

Generate a secondary table row by utilizing the ::after pseudo-element

I need to add a sub-row to the last row of the table to achieve the look shown in the photo. I am attempting to use pseudo-classes for this purpose, but I am struggling with adjusting the height of the 'tr' element to accommodate the new content. ...

Achieving a child div to occupy the entire available space when the parent is specified as `mx-auto` can be accomplished using Vue and Tailwind CSS

Sorry if this seems like a basic question, I'm still getting the hang of Vue and tailwind. In my parent template, it looks like this: <template> <div class="mx-auto mt-4 max-w-3xl"> <slot></slot> </div> ...

Three-handled slider

Just acquired a new slider component <input id="slider_price" type="text" class="span2" value="" data-slider-min="1000" data-slider-max="80000" data-slider-step="5" data-slider-value="[60000, 80000]"/> _ $('#slider_price').slider({ t ...

How can JavaScript be used to apply CSS formatting to text that appears as a new HTML element?

It's unclear if the question accurately reflects what I want to achieve. If I have a form that fades out and is then determined whether to display again through a cookie, can the confirmation message be styled using CSS? For example, I would like to ...

Guide to merging three rows from 'table one' with another table in Laravel

When working with Laravel 5.6, I encountered an issue while trying to fetch data from the database using a join query. My goal was to join multiple tables, including employee, designation, booking, and vehicles. However, I encountered the following error: ...

Executing a for loop within a foreach loop in PHP

Here is a simple array: $array = [val-1, val-2, val-3, val-4, val-5 val-6, etc] I am looking to iterate through this array using a foreach loop, but I want to group the results by 4. My goal is to place them into col-md-3 divs inside row divs. Can you pl ...

Angular with Bootstrap 4 pills - ensuring active link is maintained

Here's the navbar code snippet that I currently have: <nav class="nav nav-pills"> <a href="#" class="nav-item nav-link active" data-toggle="tab" routerLink="/home" routerLinkActive="active"> <i class="fa fa-lg fa-home"& ...

anticipating the completion of a task in order to proceed with the next one

I have been attempting to sequence the execution of two functions, but both are running concurrently with my main function. The console is displaying 2, then 1, when it should be 1 first. How can I make sure that the complete function waits for fetchingFun ...

Streamlining Your Website with AngularJS - Consolidating Multiple Files into One

As a novice in AngularJS, I encountered an issue with using grunt-contrib-less to handle less files instead of css. After installing it, I found myself having to declare all the less styles that need to be compiled into one css file. The challenge for me ...

Leveraging tailwind for achieving dynamic height responsiveness

My Tailwind-built page currently has a table in the bottom left corner that is overflowing, and I would like it to adjust its size to fit the available space and scroll from there. I want it to fit snugly in the bottom left corner of the browser viewport ...

What is the best way to display a Bootstrap pop-up and then automatically hide it after a few seconds

Does anyone know how to display a Bootstrap popup when the page loads and automatically hide it after 3 seconds? I found an example online but I'm unsure how to adapt the code for my specific needs. <button type="button" class="btn btn-primary" da ...

Using PHP code in CSS for the background styling

I'm having trouble with this line of CSS... background-image:url(upload/<?php echo $array['image']; ?>); It's not working properly, and all I see is a blank screen. The image exists in the database and on the server in the corre ...

Adjusting or cropping strokes in a JavaScript canvas

I am working with a transparent canvas size 200x200. The object is being drawn line by line on this canvas using the solid stroke method (lineTo()). I'm in need of making this object full-width either before or after ctx.stroke();. https://i.sstatic. ...

When the source is added with jQuery, the IMG element displays at 0x0 pixels

My latest project involved creating a custom modal popup named #light1. In my JavaScript code, I capture the source from the image the user clicks on and insert it into the img tag with the id of addable. Using jQuery: var images=$('#raam img') ...

Tips for ensuring that the <input type="file"> element only allows the selection of .pdf files

Is there a way to modify the default file selection behavior to only allow .pdf files to be selected? ...

Numerous CSS class attributes

I have been experimenting with creating my own custom progress bar using CSS. While the HTML5 <progress value="10" max="100"></progress> element could work, I prefer to create it from scratch. In my CSS code, I have defined the .progressbar c ...

What is the process for choosing corresponding values in jQuery?

Hello, I am a beginner in programming and I am currently working on developing a word guessing game. Here is the code I have written so far: The (letter) represents the key being typed by the player Var compareLetters = $('.letter') represents ...

What is the process for adding custom keys to a sequential array or collection of arrays with Laravel or PHP?

I'm currently exploring ways to assign custom keys to a collection in Laravel. One approach I've come across is utilizing methods like transform or mapWithKeys. $result = $collection->map(function ($item) { return [ 'custom_k ...

Showing a tooltip in Angular when a button is disabled

<button [disabled]="(!dataConceptSummmaryFlag || dataConceptSummmaryFlag === false) && (!selectedLOBFlag || selectedLOBFlag === false) && (!adsListFlag || adsListFlag === false)" class="lmn-btn lmn-btn-primary" ...