What is the best way to align image at the center of a jumbotron?

Exploring the world of bootstrap has been a fun journey, but I've hit a roadblock with the jumbotron element. No matter what I try, I can't seem to successfully add and center an image within the jumbotron using normal CSS3 techniques. Despite my research efforts, I haven't been able to find a solution...

I even assigned a class to the image and attempted to adjust its position using margins, but unfortunately, nothing seems to work. The stubborn picture just won't budge, no matter my efforts.

A big thank you in advance to anyone who can offer some guidance.

EDIT:

HTML:

<div class="middle-container-2">
  <div class="jumbotron">
    <h1 class="display-3 text-center">Go Pro. Stay on top!</h1>
    <p class="lead text-center">Premium gives you access to the Pro scrims instantly and is the only way to support the site!</p>
    <img class="mx-auto d-blok text-center unlock-icon" src="Unlock-icon.png" alt="Unlock"/>
    <hr class="my-4">
    <p class="text-center">It uses utility classes for typography and spacing to space content out within the larger container.</p>
    <p class="lead">
      <a class="read-more-button btn btn-primary btn-lg" href="#" role="button">Learn more</a>
    </p>
  </div>
</div>

CSS:

.unlock-icon {
  width: 5rem;
  height: 5rem;
  text-align: center;
}

Answer №1

To correct the styling, replace the d-blok class with the correct d-block class on your img tag. After making this change, you can delete the text-center class and apply the img-fluid class instead.

<img class="mx-auto d-block img-fluid unlock-icon" src="Unlock-icon.png" alt="Unlock"/>

Answer №2

One of the most popular tricks with Bootstrap is using text-center to align text-like contents and mx-auto to center block-level tags.

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

<div class="container">
  <div class="jumbotron">
    <h1>Bootstrap Tutorial</h1>      
    <p>Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile-first projects on the web.</p>
  
  <p>This is some text.</p>      
  <p>This is another text.</p>      
  
  <div class="text-center"><img src="https://dummyimage.com/mediumrectangle/222222/eeeeee">
  
  </div>
  
</div>

Answer №3

How to insert an image in a div and align it to the center or right

.image-holder {
    text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<div class="container">
  <div class="jumbotron">
    <h1>Bootstrap Tutorial</h1>      
    <p>Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile-first projects on the web.</p>
  
  <p>This is some text.</p>      
  <p>This is another text.</p>      
  
  <div class="image-holder"><img src="https://dummyimage.com/mediumrectangle/222222/eeeeee">
  
  </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

What is the best way to set the width of a nextjs Image using CSS styles

Do you think it's more beneficial to use 'next/image' rather than the traditional img tag? If so, why? I am trying to display an image by specifying width and height in styles using a class called 'img', like this... <img class ...

Tips for extracting both the div and entire inner content using JavaScript

I need to retrieve the inner content of a div using JavaScript For example: <div id="content" style="height: 20px; overflow: hidden"> content<br>content<br>content<br> </div> This is my HTML code. I only know the div&apos ...

What causes Chrome Extension Images to appear broken when they are inserted into the DOM?

Currently working on a Chrome extension, I am attempting to insert a div with a background image into the DOM using a content script. The CSS is loading correctly, and upon inspecting the Developer Tools, the image URL appears to be correct. $('.clos ...

Reducing image size using CSS can result in blurry images on multiple web browsers

Encountering challenges with downscaled images in multiple browsers... The images must be downscaled to adapt to the browser size. Here is the code snippet: #pic-holder img { -moz-transform: rotate(0deg); /*image-rendering:-webkit-optimize-contras ...

A button that is positioned with a low z-index may be unresponsive to

I am working on aligning an image and a button next to each other so that the image slightly overlaps the button. However, I have noticed that in doing so, the button becomes unclickable. .button{z-index:-1!important;} .image{z-index:1!important;} Any s ...

Unable to retrieve the sum total of all product items and display it in the designated text element

My product items are dynamically generated in a list. I have used the calculateItemTotal() method to determine the total for each item. Now, I need to sum up all these item totals and display the result in the total text field. However, instead of showing ...

Having issues with Inline-Block functionality?

I am facing alignment issues with an image and a container placed next to each other. The rest of my website uses inline-block without any problems. If someone could provide guidance on how to resolve this, it would be greatly appreciated. Below is the s ...

Tips for automatically adjusting the height of the footer

Is there a way to dynamically adjust the height of the footer based on the content length inside the body? I've been exploring solutions like setting the position of the footer as "fixed," but it seems to stay at the bottom of the screen, which is no ...

Clicking the ASP button does not trigger the onclick event when a web user control is included on the webpage

I have been working on a web form application that I developed using the visual studio template. The template includes a content placeholder that gets replaced by the content of each accessed page. One particular page, which contains server controls like t ...

Trigger an alert message upon loading the HTML page with search text

I need to search for specific text on a webpage and receive an alert if the text is found. <script type='text/javascript'> window.onload = function() { if ((document.documentElement.textContent || document.documentElement.innerText ...

What is the best way to place a p-growl element in the bottom right corner of the page?

I've been struggling to fix the positioning of my growl message at the bottom right corner by overriding the CSS classes of p-growl. Initially, I attempted to override the .ui-growl class like this: ::ng-deep .ui-growl { position: fixed; b ...

Switch the contenteditable HTML attribute in a dynamically generated table using PHP

Despite finding numerous articles and solutions, my code still refuses to work. What could I be overlooking? Below is a snippet of the code where the crucial part is marked at the comment '! HERE') <!-- Table with grades --> <table clas ...

How can I place this ribbon on top of an image in an HTML email to ensure it displays correctly on email clients such as Outlook?

As I delve into my research, it's becoming apparent that achieving this result might not be feasible across all email clients. However, I'm curious to know if there have been any recent developments in the email world that would allow me to repli ...

Reset the child JSP page to its original appearance

Displayed below is a JSP page: <div id="tabs-7" style="width: 100%;"> <form:form id="deviceForm" name="" modelAttribute="" enctype="multipart/form-data"> <div class="inputWidgetContainer"> <div class="inputWidget"> <table> ...

What causes a dot to display when hovering over a link in a list?

Good day. [Click here to access the test page](http://89.111.180.28/CatalogOfProductsAndServices.php) Code: <ul> <li> <a href="#">Бытовая техника</a> <ul> <li><a href="CatalogOfProductsAndServices.php ...

What is the best way to include a .AVI file in an HTML document?

I have come across some examples of .AVI in HTML on the internet. However, my page seems to be having issues. It displays fine in Chrome on my computer. But in Internet Explorer, there is a bar at the top and the videos appear blank afterwards. It ...

Tips for updating the input name in Vue.js

I need assistance with implementing a dynamic form where input names must be in array format and the array number should increase automatically for posting purposes. Here is my code snippet: <!doctype html> <html lang="{{ str_replace('_&apo ...

When hovering over an anchor, apply a border or box-shadow effect to the image

I'm trying to make an image display a border or box-shadow when hovering over a link, along with an animated circle around the round image. I've attempted to achieve this with the following CSS code, but it doesn't seem to be working. https ...

Is it possible to include both a search value and a hash in a URL?

I have created an URL ROUTER using hash (for example, #User.Account) Now I want to include a search value in it as well (e.g. #/User.Account?id=729) How can I achieve this? This is how my router currently functions: if(window.location.hash == "#U ...

Adding flair to the selected element in the HTML nav bar

I was attempting to customize the appearance of the active item within an HTML navigation bar, which corresponds to the a element. To test this out, I used the example from Here is my modified code, where I introduced a new class "active" and applied the ...