Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Jack Spangenberg
Jack Spangenberg
643 Points

Vertically aligning elements inside of a bootstrap jumbotron.

I have the following workspacee:

https://w.trhou.se/3ddyg6blyh

Keep in mind the change in color represents two different jumbotrons.

I'd like my image, "Simplism's Services" and "Services you can trust" to be vertically aligned to the center of ONLY THEIR JUMBOTRON not the entire page.

2 Answers

Ezra Siton
Ezra Siton
12,644 Points

Again! the vertical Align is not "built-in" in CSS (before flex!!), this is why you find endless idea/tricks/and styles for the same mission (google it).

You have this property but this will not work for block element (H1, DIV....) https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align

One soultion (later remove the inline-css (where you see "style=....") to your CSS file + remember to add classes to your markup):

<div class="jumbotron jumbotron-fluid jumbotron-main" id="jumbotron-1" style="position: relative;">
          <div class="container" style="
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
">
          <h1 class="display-3">Simplism's Services</h1>
          <button type="button" class="btn btn-outline-secondary">Services you can trust</button>
        </div>
      </div>
     ```
Jack Spangenberg
Jack Spangenberg
643 Points

You lost me, would you mind forking my code and demonstrating what that would look like in the code?