Create a Bootstrap jumbotron that is centered and only half of the width

I have a unique password reset method here: Jumbotron-Form-Bootstrap-My-Attempt

Displayed below is the code from the image above:

<div class="container">
    <div class="jumbotron">
        <br><br>
        <h2>Forget Password</h2>
        <br><br>
        <div class="alert alert-info" style="margin-top:18px;">
            <a class="close" href="#" data-dismiss="alert" aria-label="close" title="close">&times;</a>
            <strong>Info!</strong>
            Please enter your email address. You will receive a link to create a new password via email.!
        </div>
        <div>
            <?php if(isset($msg)) { echo $msg; } ?>
        </div>
        <br>
        <form method="post">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="emailUsername">Email or Username:</label>
                        <input name="email" type="text" class="form-control" id="emailUsername" placeholder="Enter your Email or Username">
                    </div>
                </div>
            </div>
            <br>
            <button name="submit" type="submit" class="btn btn-default">Submit</button>
        </form>
    </div>
</div>

To achieve the desired look as shown here: Jumbotron-Form-Bootstrap-Wanted but maintained within a jumbotron for aesthetic purposes.

My current query is: How can I centrally align the jumbotron (or any special class for this purpose) both vertically and horizontally on all devices, so it appears in the middle of the page consistently?

I attempted

.jumbotron {
      max-width: 500px;
      margin: 0 auto;
 }

but noticed that this adjustment caused the input field to shrink.

Answer №1

One way to vertically center using CSS is by applying the .vertical-center class:

.vertical-center {
  min-height: 100%; 
  min-height: 100vh;    
  display: flex;
  align-items: center;
}

For horizontal centering, you can use Bootstrap's grid system with classes like col-??-# and col-??-offset-#.

To combine these concepts, wrap your Jumbotron in a container div with the vertical-center class and apply appropriate Bootstrap grid classes:

<div class="container vertical-center">
  <div class="col-md-6 col-md-offset-3">
    <div class="jumbotron">
      <!-- Your code here -->
    </div>
  </div>
</div>

Check out a working example here.
You can also adjust the grid classes for different screen sizes, like using xs for phones.

Answer №2

<div class="wrapper" style="width:30%;">

Experiment with different percentage values to adjust the width of the container to your liking. By combining default bootstrap styles with custom CSS, you can achieve the desired size and layout for your elements.

Answer №3

To center content vertically, simply nest a .row div inside a .container and add a div with classes col-md-6 and col-md-offset-3 inside the row before inserting your jumbotron div.

<div class="container vertical-center">
    <div class="row">
        <div class="col-md-6">
            <div class="jumbotron">
            </div>
        </div>
    </div>
 </div>

For vertical centering, utilize a CSS3 trick involving the translate() function:

.container .vertical-center{
  width: 50%;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}

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 create an animation for changing .text in response to an on click event?

I'm currently developing a simple calculator that increases a variable when a button is clicked, displaying the updated value in a div. Each click on the 'amount-upwards' button adds 200 to the displayed number. Below is the jQuery code I a ...

Embedding a picture logo within a CSS-designed content box

I am trying to create a unique layout for my website that reveals content using labelled radio buttons, without the use of scripts. Instead of using <a href='#'>, I want to achieve a specific layout like the one shown in this example. When ...

Chrome miscalculates the dimensions of the screen

This is my first attempt at working with responsive design, and I seem to have encountered a bug. When I shift part of the browser off-screen and expand it to around 1345 pixels, it seems to trigger the CSS set for 1224 pixels. //Currently, only @media al ...

Ways to ensure next/image takes up all available grid space

Is there a way to make the next/image element span from grid 1 through 8? It seems to work fine with the imgtag but not with next/image. .project { display: grid; margin-bottom: 4rem; grid-template-columns: repeat(12, 1fr); align-items: center; } ...

What are some ways to modify the appearance of the post title table using CSS?

In this snippet of HTML code- <table style='min-width:60%;height:25px;'> <tr> <td><b><data:post.title></b></td> <td id='date-and-author' style='position: relative;bo ...

I'm having trouble getting Firefox to recognize the percentage height set on table rows. Any suggestions for a workaround?

The goal is to set the height of the first row to 70% of the screen. To prevent the scrollbar from appearing on the entire webpage, overflow has been set to auto within the div of the first row. This solution functions correctly on Chrome and IE, however, ...

Menu bar placed atop a carousel

I am currently in the process of developing a website and I have encountered an issue with the navigation bar. I have a slider that I would like to appear below the navbar but the navbar is pushing it down instead. Ideally, I want the navbar to be transpar ...

What is the best way to modify the CSS of a child element within the context of "$(this)"

On my search results page, each result has an icon to add it to a group. The groups are listed in a hidden UL element on the page with display:none. The issue I'm facing is that when I click on the icon for one result, the UL appears under every sing ...

Vertically animating an image using jQuery

I have been experimenting with trying to make an image appear as if it is floating by using jQuery to animate it vertically. After some research, I stumbled upon this thread: Animating a div up and down repeatedly which seems to have the solution I need. H ...

Enhance the dropdown menu by incorporating a caret icon

Click here for the image, I am trying to incorporate the Bootstrap caret class into my select dropdown menu. .select_menu{ font-size: 12px; outline: none; border: thin #ddd solid; -webkit-appearance: none; -moz-appearance: none; appearance: ...

Ineffectiveness of Less Guard feature

I have a mixin with a guard clause that I've implemented following the provided guidelines. According to the syntax below, @palette should be selected from a list of custom colors and @color should be assigned a value from a specific set. The curren ...

When adjusting to mobile dimensions, the responsive website design struggles to center the navbar properly

I am currently developing my senior year portfolio website and I am struggling to center the navbar (Work About Contact) when it is in mobile mode. My goal is for it to be positioned directly below the logo, perfectly centered, but so far nothing I have tr ...

Tips on eliminating borders in react-table components

Within my React.js component, I have implemented a table using react-table along with some material-ui components displayed alongside the table: import React from 'react' import { useTable, useGlobalFilter, usePagination } from 'react-table& ...

Activate hover effect on toggle button

When I hover over the "CHANGE" button, the orange color appears as expected. Clicking the button once turns the color red but removes the hover color, which is fine. However, clicking it twice brings back the original blue color but the hover effect is m ...

Adjust all children's height to match that of the tallest child

My nearly completed jQuery slideshow is working well except for one issue - the height of the slideshow remains fixed at the height of the first displayed slide, causing problems. View the issue here: . I have tried different jQuery solutions from StackOve ...

Designing a scrollbar for a tr element using HTML and CSS

I am struggling to create a scrollbar for the inner table that is not being displayed within its container. The container has a yellow background while the table itself is blue. My goal is to have a scroll bar specifically within the table. For more info ...

Troubleshooting CSS Problems: Issues with background repeating and footer placement

I am currently in the process of transitioning my website to a CSS layout, and so far it's looking good. However, I am facing two specific issues with the page layout that I need help with: 1) The background image of the left-most column is not repea ...

Creating a unique look for unordered list items in a dropdown navigation

I'm currently working on creating a drop-down menu using nested unordered lists. The functionality of the menu is all set, but I'm running into some styling issues. The main link that triggers the drop-down should have a blue background with whit ...

Tips for creating a sub-menu within a dropdown menu

I need some help adding a sub-menu to my drop-down function. I'm not very familiar with CSS, so I'm struggling to figure out how to do it. Ideally, I want the sub-menu to open to the right when the cursor hovers over it. Below is the CSS and HTML ...

Inline styles are effective, but external stylesheets are not functioning properly (see JsFiddle for reference)

http://jsfiddle.net/xw0vvo9e/4/ Trying to specify a background color for the navBar. In the provided jsfiddle, the CSS includes: div .navBar { width: 100%; height: 45px; background-color: #FF0000; top: 0px; position: fixed; } However, the background ...