What is the best way to align images in the center using Bootstrap?

Hello there stackoverflow

I've been attempting to align those images in the center. I've tried all the suggestions I could find about vertically centering in bootstrap.

http://jsfiddle.net/tLd85urn/41/

You can view my source code here. When I remove the "div" and "html" lines in the CSS stylesheet (height: 100%;), the images appear centered, but then the entire page loses its fullscreen layout. Is there a way to center those images while maintaining the "fullscreen" design?

html,
body {
  height: 100%;
  /* If I remove this line, it works, but it's no longer fullscreen */
  width: 100%;
  margin: 0;
}

div {
  height: 100%;
  /* If I remove this line, it works, but it's no longer fullscreen */
  /*width: 100%; */
  margin: 0;
}

.header {
  height: 10% !important;
}

.content {
  height: 80% !important;
}

.footer {
  height: 10% !important;
}
<div class="container-fluid">
  <div class="row header text-center align-items-center align-middle">
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
    <div class="col-xl-8 col-lg-8 col-md-8 col-sm-6 col-6" style="background-color:lavenderblush;">.col-lg-8</div>
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
  </div>
  <div class="row content text-center align-items-center align-middle">
    <div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="background-color:lavender;">.col-lg-1</div>
    <div class="align-items-center align-middle col-xl-10 col-lg-10 col-md-10 col-sm-10 col-10" style="background-color:blue;">.col-lg-10<img src="test2.png" class="align-items-center align-middle img-fluid rounded mx-auto" alt="Responsive image"><img src="test2.png" class="img-fluid mx-auto" alt="Responsive image"><img src="test2.png" class="img-fluid mx-auto" alt="Responsive image"></div>
    <div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="background-color:lavender;">.col-lg-1</div>
  </div>
  <div class="row footer text-center">
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
    <div class="col-xl-8 col-lg-8 col-md-8 col-sm-6 col-6" style="background-color:lavenderblush;">.col-lg-8</div>
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
  </div>
</div>

In the end, I'd like it to look like this:

Thank you for your assistance and best wishes,

Tine

Answer №1

To make the container with 3 images centered, add the class d-flex justify-content-center

html,
body {
  height: 100%;
  width: 100%;
  /* Removing this line will no longer make it fullscreen */
  margin: 0;
}

div {
  height: 100%;
  /*width: 100%; */
  margin: 0;
}

.header {
  height: 10% !important;
}

.content {
  height: 80% !important;
}

.footer {
  height: 10% !important;
}
<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->
<link rel="stylesheet" type="text/css" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<div class="container-fluid">
  <div class="row header text-center align-items-center align-middle">
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
    <div class="col-xl-8 col-lg-8 col-md-8 col-sm-6 col-6" style="background-color:lavenderblush;">.col-lg-8</div>
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
  </div>
  <div class="row content text-center align-items-center align-middle">
    <div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="background-color:lavender;">.col-lg-1</div>
    <div class="align-items-center align-middle col-xl-10 col-lg-10 col-md-10 col-sm-10 col-10 d-flex justify-content-center" style="background-color:blue;">.col-lg-10<img ...class="img-fluid mx-auto" alt="Responsive image"><img ....class="img-fluid mx-auto" alt="Responsive image"><img src="data:image/svg+xml;charset=UTF-8,%3Csvg....class="img-fluid mx-auto" alt="Responsive image"></div>
    <div class="col-xl-1 col-lg-1 col-md-1 col-sm-1 col-1" style="background-color:lavender;">.col-lg-1</div>
  </div>
  <div class="row footer text-center">
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2</div>
    <div class="col-xl-8 col-lg-8 col-md-8 col-sm-6 col-6" style="background-color:lavenderblush;">.col-lg-8</div>
    <div class="col-xl-2 col-lg-2 col-md-2 col-sm-3 col-3" style="background-color:lavender;">.col-lg-2<img src="test3.png" class="img-fluid rounded mx-auto" alt="Responsive image"></div>
  </div>
</div>

Answer №2

<div class="container-fluid" style=background-color:lavender>
  <div class="row text-center">
    <div class="col">
      picture1
    </div>
    <div class="col">
    picture2
    </div>
    <div class="col">
    picture3
    </div>
  </div>
</div>

Hey, have you come across something similar to this? This is what I put together for your question.

Answer №3

Understanding the functionality of Bootstrap's grid system is crucial. It is essential to grasp when content will stack vertically after reaching a certain breakpoint. The code below provides a modification that may enhance your comprehension:

Utilizing Bootstrap classes (col-md-4, lg-8, etc) simplifies resizing tasks. To center an image, implement the following CSS rules:

CSS

img{
 height: auto;
 width: 100%;
 }

By adopting these rules, your image will occupy the entire width of the div. Refer to the provided link for the complete code.

Feel free to view the updated fiddle here.

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

Guidelines for choosing an Element Id within an attribute tag using jQuery

Check Output and -->question. . I am a beginner in utilizing Bootstrap and JQuery for programming. I am interested in learning how to identify the "id" of an input element that is nested within another element's attribute. In my code, I am using ...

Display sub navigation when clicked in WordPress

I currently have the default wordpress menu setup to display sub navigation links on hover, but I am interested in changing it so that the sub navigation only appears when the user clicks on the parent link. You can view my menu here https://jsfiddle.net/f ...

Connect button with entry field

I want to create a connection between an input element and a button, where the button triggers the input and the input remains hidden. Here is a solution that I came across: <a href="javascript:void(0)" id="files" href=""> <button id="uploadDe ...

Creating a gallery using an array with jQuery

I have a list of image links in an array that I want to use JavaScript (with jQuery library) to format the HTML output like this: <div id="gallery"> <div class="scrollable"> <div class="items"> <div> < ...

Steps for Aligning the Label and Textbox Horizontally

<div class="form-group row"> <div class="col-6 "> <h4> <label class=""> Can you meet the required amount of money? @(HelpSeeker.money_needed= He ...

Managing multiple forms within a Django template loop

Struggling with handling forms in django template for loop using jquery {% for comment in commets %} <!-- reply to comment --> <form id="replyform" action="" method="POST"> <input type="hidden" name="comment-id" value="{{comment.id}}"> ...

creating a select box that changes dynamically based on the form submission

My current project involves developing an upload form where users can upload documents along with additional details such as the document name. The challenge I am facing is related to generating a secondary select box based on the category chosen by the us ...

JavaScript functions may become unresponsive following ajax loading with tables

I have a table that is automatically generated by a database using PHP with four rows. The last row (4) has a button that triggers the function below, and this is repeated for every line. After clicking the button, the script sends a request to update the ...

Having trouble with CSS and javascript files not resolving after moving app to a new Windows 7 development machine

I have recently migrated my ASP.Net 3.5 web site from my old XP sp3 machine to a new Win 7 64-bit dev machine. The web application utilizes Master Pages, App_Themes with style sheets and images, as well as an image folder located off the main root. Additio ...

Tracking employee work hours using a combination of PHP, Ajax, and Mysql technology

I am working on developing a code that allows my colleagues to clock in and out. The process involves selecting the month of birth first, after which all names corresponding to that month are displayed. This data is retrieved from a database. The current ...

Showing information from MySQL database utilizing jQuery and AJAX

Seeking advice as a newcomer trying to create a simple application that utilizes JavaScript, jQuery, and JSON objects to display a MYSQL table. Despite the absence of errors, I am unsure of how to progress with my project. Any insights you can offer would ...

Learning SQL and PHP is essential for displaying data from a database in a dynamic table on a web page. In order to select specific columns from the database and arrange them in

I am working with a sql table called res that contains various rows and columns. Here is an example of the data: Sno RegNo Name sub1 sub2 sub3 total percent result color 1 1DU12CS100 s1 10 10 10 30 50 fail danger 2 ...

Manipulate various textboxes and selects with jQuery to gather data from each row individually

Is it possible to use jQuery to display a select dropdown and text box based on a loop count? For example, if I select USD from the dropdown, the text box will display "US Dollars" and if I select JPY, the text box will display "Japan Yen" and so on for su ...

What could be causing the misalignment of my select box in Bootstrap framework?

I'm currently trying to replicate the layout of the second image shown below, as seen in the first image. However, I'm facing an issue with the positioning of the selection box and I can't seem to figure out why. I've experimented wit ...

Making Adjustments to the Padding of Main Content Column in Typo3 Using Bootstrap Package

As the administrator of our local sports club's homepage, I oversee svwalddorf.de, powered by typo3 10.4.22 with bootstrap package 11.0.3. The current bootstrap template creates excessive empty space around the centered content area as shown here. Th ...

reduce opacity of specified div background

Objective / Purpose I am working with multiple div elements and I want to assign two distinct classes to each of them, each serving a different purpose within my application. One class should determine the level, influencing the color of the div. The oth ...

Can using display: none impact the SEO of a website's navigation menu?

Is there a difference in SEO impact between using display:none with CSS and using display:none with jQuery for menus? Appreciate the insights! ...

Discover the steps for dynamically integrating ionRangeSliders into your project

Recently, I integrated ionRangeSlider to display values to users using sliders. To set up a slider, we need to define an input tag like this: <input type="text" id="range_26" /> Then, we have to use jQuery to reference the input tag's ID in or ...

Function not being triggered by button

We are struggling to get a button to trigger a function upon being clicked. Is there a reason why the function is not being called? <body> <button onclick="instagramclick()">Login to instagram</button> <button onclick="myFunction( ...

What is the best way to close the gap between the bottom border and text elements?

Currently in the process of developing my website and encountering an issue. Check out the webpage here. I aim to apply 3px underlines solely to the links, like so: The line height for the text stands at 56pt, causing the border-bottom to be significantl ...