Aligning text in the middle vertically using a display:flex container

I am working on a calendar mobile webapp that utilizes jQuery Mobile Grid. Each cell in the grid may contain up to three blocks representing a schedule, which I want to expand to fill the parent cell using the display:flex property.

However, I am having difficulty centering text vertically within these blocks as the height is not directly specified. None of the methods I have tried so far seem to work in achieving this.

Below is a snippet of the code:

<div class="ui-grid-d">
     <div class="ui-block-a">
            <div class="ui-bar dia-block">
                <span class="dia_titulo"> 1</span>
                <div class="ui-grid-a turno-grid-container">

                        <div class="ui-block-a turno-block manana">M</div>
                             <div class="ui-block-a turno-block manana">T</div>
                             <div class="ui-block-a turno-block manana">N</div>
                </div>
            </div>
        </div>
     ....
</div>

CSS: (turno-block should be used for centering the text) .turno-grid-container { display: flex; flex-direction: column; height: 100%;

}

.turno-grid-container>div {
    flex: 1;
    justify-content: center;
    flex-direction: column;
}

.turno-block {
    height: 100%;
    width: 100% !important;
    color: #FFF;
    text-align: center;
    line-height: 100%;
    border-bottom: 1px solid white;
}

For reference, here is a fiddle demonstrating the issue (the text "M", "T" should be centered): http://jsfiddle.net/kelmer/36xkggvc/2/

Answer №1

.turno-grid-container>div {
   flex: 1;
   justify-content: center;
   flex-direction: column;
   align-items: center; <-- include this line for alignment
   display: flex; <-- ensure to add this for proper layout
}

Check out the demo here - http://jsfiddle.net/36xkggvc/6/

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 method for utilizing an autocomplete plugin to update a div element?

I am seeking assistance regarding implementing an autocomplete feature in a DIV that displays the names, images and ages of other users as they are typed into a field positioned above the DIV. I want this autocomplete functionality to mimic Facebook' ...

Create and start a new Google map after an AJAX update of a partial

I have successfully displayed a google map with markers, but I am facing an issue when trying to display the map within a partial that is refreshed using ajax. It seems like the final initialization line at the end of the code is not firing when using ajax ...

How can I integrate a timer into an Angular carousel feature?

I have put together a carousel based on a tutorial I found on a website. Check out the HTML code for my carousel below: <div class="row carousel" (mouseover)="mouseCheck()"> <!-- For the prev control button ...

Retrieving plain text content from HTML while preserving both ordered and unordered lists in Node.js

My goal is to extract plain text from HTML code while preserving the numbering from ordered or unordered lists. However, existing libraries like node-html-parser and cheerio do not maintain this information. To clarify, consider the following HTML: < ...

Fulfill the promise within the function upon clicking the button

I've created an intricate 'slideshow' using popups within a vue.js template. Each slide is a separate component, and the parent component cycles through them in a 'for' loop. Users navigate from one slide to the next by clicking a ...

How about a fading effect for the select box?

I'm currently working on creating a select tag that opens its options slowly with a fade in, fade out effect when the user clicks on "Actions." I've attempted to use jQuery for this feature but haven't had any luck. Here's my code: &l ...

The issue of why a hyphenated id selector does not function properly in javascript

Just delving into the world of JavaScript, I recently started learning how to code in this language. Currently, I am working on a JavaScript function that counts characters. Javascript function CheckFieldLength(fn, wn, rn, mc) { var len = fn.value.leng ...

Integrate a scaling feature into an HTML webpage

I am having trouble with the columns in my div not being equal widths. Does anyone have any suggestions on how to fix this issue? Does anyone know of a better way to create a scale using div elements instead of tables? <DIV class="scale"> <D ...

Is there a way to transfer controller scope to a partial HTML file?

Welcome to my HTML setup <div ng-controller="filterController"> <div class="quick-view" id="quickview" data-toggle="modal" data-target="#modal-bar" ng-click="quickView(quickview)"><i class="fa fa-eye"& ...

Tips for submitting an AJAX form in grails without relying on a traditional submit button

I am utilizing a g:formRemote tag to submit a form via ajax. <g:formRemote name="listAll" update="menuItemAJAX" url="[controller: 'superWaiter', action:'menuItem']" onSuccess="additionalContent()"> <a h ...

What is the best way to disable the click function for <a> tags that have a specific class?

I am dealing with parent navigation items that have children, and I want to prevent the parent items from being clickable. Here is an example of how they currently look: <a href="parent">Parent Item</a> Is there a way to select the <a> ...

Organize data in a Vue.js table

Currently facing an issue with sorting my table in vue.js. Looking to organize the table so that campaigns with the highest spend are displayed at the top in descending order. Here is the code I'm working with: <template> <div class=" ...

View the Outcome of the Latest Form Submission on a Fresh Page

I have created a form that stores input values in a database table. Now, I want to display these results on another page once the form is submitted. However, I am struggling with how to retrieve and display all the values from the database record on the ne ...

Encountered an issue when utilizing Yahoo PlaceFinder API and jQuery to retrieve data in json format

Currently, I am integrating Yahoo API into my project. Initially, working with the Yahoo GeoPlanet in json format using jQuery was a seamless process. However, I have encountered issues while trying to implement the Yahoo PlaceFinder API with jQuery in jso ...

Are there any other default light colors in CSS aside from "gray"?

Seeking recommendations for background color combinations. The more suggestions, the better! Thank you :) ...

Dividing and arranging dropdown list items into two columns using Bootstrap - An easy guide

How can I split a dropdown ul>li list into two columns using Bootstrap? I am attempting to divide the ul>li into two columns, with one aligning to the left and the other to the right. This is how I am currently doing it: <div class="btn-group" ...

How do I stop Bootstrap from taking over my custom navbar design?

My website's navbar stopped working after adding Bootstrap to my HTML pages. I suspect that Bootstrap is overriding my custom CSS. Here is the code for my navbar: .navbar { overflow: hidden; !important; background-color: #333; !important; } .. ...

I can't seem to figure out why my Angular 10 select element is not showing the data I've assigned to it. Can someone help me

I'm currently facing an issue with a select element in the HTML template of my Angular project. The problem stems from having a JSON file containing all countries data. Languages Interface export interface Country{ name:string code:string } ...

Executing multiple server-side methods on an AJAX call in ASP.NET MVC: A comprehensive guide

I am facing a situation where I have a method that is called by jQuery, and its result is displayed on a popup. Sometimes, it takes some time to complete and a blank popup appears with processing message. When clicking on close, the popup disappears but th ...

Checking for blank text inputs within a row of a table

Currently, I have a bootstrap modal that is filled with data from the database when there are rows to display (First Name, Last Name, Class Rank). Before saving the data, I can add and remove rows. My goal is to collect the table's data and create a ...