Align the dynamic content in the center vertically

Despite my extensive search on the internet, I have not been able to resolve my issue. The typical solution for vertically centering dynamic content in a div does not seem to work for me. It appears that something in my code is different from the examples provided.

You can find the webpage in question here:

The problem lies within the first yellow section of the page. I am trying to achieve vertical center alignment for both the text on the left (which may vary in length) and the white box on the right.

Currently, the HTML structure looks like this:

<div class="container yellow-content">
    <div class="row center-vertical">
        <div class="col-md-7 vertical-center-element">
            <h2>Actie en avontuur</h2>
            <p>
                540 smith grind grind hang up launch ramp. Sponsored gnarly no comply regular footed hang-up. Quarter pipe tic-tac aerial hang ten airwalk. Deck baseplate crail grab bluntslide regular footed. Varial carve darkslide ollie hole Vans Calfornia Daze rocket air. Pivot kick-nose ollie sketchy death box Steve Rocco.
            </p>
        </div>
        <div class="col-md-3 col-md-offset-1 bgwhite vertical-center-element">
            <div class="row text-center">
                <div class="col-md-6 col-md-offset-3">
                    <div class="text-center testimonial">
                        <a href=""> <img class="img-circle img-responsive" src="../img/reisaanbod/testimonials/testi_canyoning.jpg" alt=""> </a>
                    </div>
                </div>
            </div>
            <div class="row text-center">
                <div class="row-md-9">
                        <p>Tic-tac nollie bearings Ron Allen disaster. Downhill blunt no comply Kevin Jarvis slob air. Deck Brooklyn Banks indy grab slap maxwell pop shove-it.</p>
                </div>
            </div>
        </div>
    </div>
</div>

The important CSS styles are as follows:

.row.center-vertical{
    display: table;
}
.vertical-center-element{
    display: table-cell;
    vertical-align: middle;
}

I am unable to pinpoint the error causing the centering issue. Any assistance would be greatly appreciated!

Thank you in advance!

Answer №1

Make a modification

.vertical-center-element{
    display: table-cell;
    vertical-align: middle;
}

to

.vertical-center-element {
    display: inline-block;
    vertical-align: middle;
    float: none;
}

The issue arises from having float: left on the element, preventing proper vertical alignment. The addition of float:none in the code above will resolve this.

I hope this explanation clarifies things for you.

UPDATE

In this case, consider changing:

<div class="col-md-7 vertical-center-element">
        <h2>Action and Adventure</h2>

to (PLEASE NOTE col-md-8 instead of col-md-7)

<div class="col-md-8 vertical-center-element vertical-centered-text">
        <h2>Action and Adventure</h2>

and include the following adjustments in your CSS:

.vertical-center-element {
    display: inline-block;
    vertical-align: middle;
    float: none;
}

.vertical-centered-text {
    padding-right: 60px;
}

With these changes, all your elements will align correctly, and your text will be positioned as intended. Moreover, by minimizing alterations to the CSS, you can avoid unexpected shifts in the bootstrap grid when scaling down, among other benefits.

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

Working with the collapse event in Bootstrap

After purchasing a template from ThemeForest, I found it to be absolutely amazing. However, I am struggling with using Bootstrap as it seems quite complex. The left menu is structured with collapsible ul and multiple li elements. I am seeking assistance o ...

Unusual Conduct when Interacting with ContentEditable Text

Looking for help with a strange issue that I can't seem to figure out. Hopefully someone has encountered this before and might have a solution. In my Angular app, I'm using a contenteditable <div> for inputting content, which is working fi ...

Styling the content within Template Strings is not supported by VSCode

Recently, I've noticed that there are two scenarios in which my VSCode doesn't properly style the content within my template strings. One is when I'm writing CSS in a JavaScript file, and the other is when I'm fetching data from GraphQL ...

Instead of only one menu icon, now there are three menu icons displayed on the screen. (Additionally, two more divs containing

When visiting on a smartphone browser, you may notice that instead of one menu icon, three icons appear. Upon inspecting the elements, you will find that there are three div's that look like this: <div class="responsive-menu-icon">&l ...

Designing the presentation of two overflowing text containers positioned next to each other

Hey there, I'm currently working on styling something that shows both the user's username and the title of an item on the same line, similar to how it's done on GitHub: username / title I want to make sure that if the combined width of the ...

Limiting the scrolling capability within a flex container by using the nowrap

When using flex with nowrap, it appears that the horizontal scroll bar only allows moving to the right while the items on the left remain hidden. To demonstrate this issue, I have created a sample on CodePen: http://codepen.io/anon/pen/QpgvoZ This behavio ...

What strategies can we implement to ensure consistency in visual styles and templates across our microservices?

Our team is currently working on multiple microservices simultaneously. While traditional microservice architecture discourages code sharing and reuse between services, we are considering the benefits of consistent styling across all services that have Web ...

Personalize the Hover color on your flexdashboard with a touch of custom CSS

I am currently working on building a dashboard with Flexdashboard and I want to customize the hover and active colors of the Flexdashboard pages named Capture and Results with specific colors that are unique to the client. I prefer not to use the default F ...

Having trouble with animating the background color of an input button using jQuery?

I'm completely confused as to why the background color isn't changing despite investing a significant amount of time into it: <input type="button" class="front-consultation-btn" value="Get A Free Consultation"> <script> $(' ...

Having trouble retrieving the value from the input text in a dynamically generated table

How can I retrieve values from a dynamically generated table after clicking a button? Below is the code I have implemented to create a table with input fields: function createTable(rows, cols){ var body = document.body, table = document.createEl ...

Upgrade the old website by incorporating some components of the Framework CSS

Having experience with bootstrap, semanticUI, foundation, and other frameworks, my new project involves adding features to an existing website without rebuilding it entirely. I am looking to implement a partial view using a framework's CSS. How can I ...

Is there a way to eliminate the bottom border on the active navigation tab?

Here's the information I've gathered: Below is a snippet of code that I have: .nav-tabs { border-bottom: 3px solid #3FA2F7 !important; } .nav-tabs .nav-link { color: #02194A; font-size: 13px; padding: 12.5px !important; } ...

What is the best way to update the color of an fa icon when an error message is displayed using PHP

I am facing an issue with my form where error messages are displayed on certain input fields. The error messages show up correctly, but I want to change the color of the "fa" icon in the field when its corresponding error message appears. My goal is to ma ...

Using D3-GraphViz in Javascript along with an Angular template: A step-by-step guide

I am attempting to integrate d3-graphviz following the guidance provided here within an angular template, like in this example. The tutorial on the d3-graphviz website advises me to include the following code in the index.html file: <!DOCTYPE html> & ...

Utilizing VueJS to choose an item from a list and exhibit it using a function

My goal is to retrieve the element I click on, displayed in a list, and then print this element using a method within my Vue instance through the mail-list tag in index.html. I have a Vue component that iterates over a JSON object and only displays two at ...

The selection feature is not supported for the type of input element in jQuery

I'm currently attempting to utilize AJAX to send a form with jQuery. However, upon clicking the submit button (which is technically a link), I encountered an error. The error displayed in the console is as follows: Failed to read the 'selection ...

How can I create a unique overlay popup for each item in an iterated list using Django template?

Generating an iterated list of titles from context received by the template in Django is simple: {% for instance in object_list %} <li>{{instance.international_title}} </li> {% endfor %} CSS makes it easy to create a popup overlay as well: # ...

What is the best way to extract the text from a <div> tag and show it in a different div when clicked on using ng click in AngularJS?

When the button is clicked, the text in ng-model=name should be displayed in the <h2> tag. <div ng-model="name">This is a text</div> <button ng-click="getname()">Click</button> <h2>{{name}}</h2> ...

CSS overflowing issue causing inability to reach bottom of div with scroll bars not functioning as anticipated

My objective is to create a layout featuring a sticky header and left sidebar, with a non-sticky DashboardBody (the green-bordered box) that can be scrolled through. When scrolling, I want the content at the top to disappear "under" the sticky header. The ...

"Present a continuous sequence of images in HTML to create a dynamic video-like experience

A PHP file has been created to extract images from a MySQL database and display them as a sequence of images that update every half second. Using the setInterval method in JavaScript, the page is refreshed every half second to display a new picture. $(doc ...