Vertical Alignment of Text within a DIV

I'm looking to center text vertically in all screen resolutions. Does anyone have suggestions?

https://i.sstatic.net/DHuE0.jpg

Answer №1

Take a look at the code snippet below:

.textBox{display: flex;align-items: center;justify-content: center;}
.cont-bx1{background-color:#9f2f1f; color:#ffffff; text-align:center;  min-height:200px; font-weight:bold; border: 1px solid #ffffff;}
.cont-bx2{background-color:#ef9030; color:#ffffff; text-align:center; min-height:200px; font-weight:bold; border: 1px solid #ffffff;}
.cont-bx3{background-color:#df6221; color:#ffffff; text-align:center; min-height:200px; font-weight:bold; border: 1px solid #ffffff;}
.cont-bx4{background-color:#df6221;  color:#ffffff; text-aligncenter;  min-height:200px; font-weight:bold; border: 1px solid #ffffff; }
.cont-bx5{background-color:#9f2f1f; color:#ffffff; text-align:center; min-height:200px; font-weight:bold; border: 1px solid #ffffff;}
.cont-bx6{background-color:#9f2f1f; color:#ffffff; text-align:center; min-height:200px; font-weight:bold; border: 1px solid #ffffff;}
.cont-bx7{background-color:#ef9030; color:#ffffff; text-align:center; min-height:200px; font-weight:bold; border: 1px solid #ffffff;}
.cont-bx8{background-color:#df6221; color:#ffffff; text-align:center; min-height:200px; font-weight:bold; border: 1px solid #ffffff;}
<div class="col-lg-12">
<div class="col-lg-4 cont-bx1 textBox">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
<div class="col-lg-4 cont-bx2 textBox">Lorem ipsum dolor sit amet, consectetur</div>
<div class="col-lg-4 cont-bx3 textBox">Lorem ipsum dolor sit amet, consectetur adipiscing</div>
</div>
<div class="col-lg-12">
<div class="col-lg-6 cont-bx4 textBox">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
<div class="col-lg-6 cont-bx5 textBox">Lorem ipsum dolor sit amet, consectetur adipiscing</div>
</div>
<div class="col-lg-12">
<div class="col-lg-4 cont-bx6 textBox">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div>
<div class="col-lg-4 cont-bx7 textBox">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do</div>
<div class="col-lg-4 cont-bx8 textBox">Lorem ipsum dolor sit amet</div>
</div>

Answer №2

Flexbox is a powerful tool for aligning items in web design.

  display: flex;
  align-items: center;
  justify-content: center;

To see it in action, check out this complete example on codepen

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

Personalizing the dimensions of audio.js

I recently integrated the audio.js plugin into my website. I've added the necessary code to the header.php file located in the includes folder. <script src="audio/audiojs/audio.min.js"></script> While the player appears correctly on othe ...

How to make Jquery skip over elements with a particular data attribute

I am looking to select all elements that are labeled with the 'tag' class. Once these items have been selected, I would like to remove any items from the list that contain the attribute 'data-tag-cat'. var tags = $('.tag'); c ...

Aligning input fields vertically and horizontally within a div container

Struggling with this frustrating piece of code for hours now. I've lost nearly 2 hours trying to get it to work properly. My goal is to center an input field vertically and horizontally inside a horizontal bar. Take a look at the simplified code belo ...

I encounter a difficulty in changing the background color when I click on the horizontal navigation menu, as it does not display the currently selected menu

.unorder_Hnav,li,.classes:active { background-color:#7CA738; height: 50px; display: table-cell; width: 1024px; text-align: center; line-height: 52px; font-weight: bolder; color: #FFFFFF; background-color: #457025; ...

Transform your image using the Bootstrap framework

I am attempting to create a similar banner using bootstrap. You can view the demo of the banner here. https://i.stack.imgur.com/JXLNY.png I'm struggling to understand how to achieve this in bootstrap 3 and where to begin. Should I use rows and colum ...

Clearing user's browsing data

I managed to successfully set up a user cookie, but I'm having trouble getting it to be destroyed or terminated when the user logs out. Any assistance on this matter would be highly appreciated! I am new to PHP and still in the learning process. Here ...

Are there any specific CSS classes or directives in Angular for disabled controls in Reactive forms?

I am dynamically disabling controls in a reactive form based on specific conditions. I also wish to apply custom styling to those disabled controls. Does Angular automatically add a CSS class or directive to disabled controls? I have not come across any. ...

In a remarkable design with an array of buttons and an individual div assigned to each, a fascinating functionality unfolds. Whenever a

https://i.stack.imgur.com/emhsT.png When I click on the first "Respond" button, I want the adjacent text box to disappear. Currently, if I click on the first "Respond" button, both text boxes will disappear instead of just the first one. $('.comment ...

Can someone explain why the min-width property is not being respected by the <input> element?

Visit this link for the code The text field in the provided link should only be 10px wide but it is currently displaying a width of 152px. Here is the code snippet: .input { width: 100%; box-sizing: border-box; } .cont { padding: 2px; } .main ...

Transform the given string into an array by eliminating all instances of the plus symbol

I need help converting strings into an array by removing the "+" characters. Currently, it is only converting the first element and not all of them. Can you assist me in converting all instances of "+" to "," for every element? let myString = 'jan + f ...

Order of operations for applying SVG transforms

According to the W3C specification, the 'transform' attribute consists of a <transform-list>, which is essentially a list of transform definitions that are applied in the specified order. If a list of transforms is provided, each transfor ...

Prevent dropdown from closing when clicking outside of it

Ensure the dropdown remains open when clicking outside of it. Display and hide dropdown only when button is clicked. Check out the JSFiddle link. <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggl ...

What could be causing my centrally-aligned divs to not scroll horizontally?

(Please note that there are no scrollbars on these divs, so scrolling to the left is not possible within the body or the divs themselves.) The issue (shown above in FF and Opera) occurs on both the "Baroque" and "Spotlights" theme selections (refer to the ...

JQuery is not able to render Hindi content properly

I am attempting to showcase some Hindi words using JQuery because these are essential contents that need to be displayed on every page of the website. Please note that this is a static website built with HTML and JQuery/JavaScript. Below is my JS file: in ...

Enhance your HTML rendering with Vue.js directives

Check out this cool code example I created. It's a simple tabs system built using Vue.js. Every tab pulls its content from an array like this: var tabs = [ { title: "Pictures", content: "Pictures content" }, { title: "Music", c ...

The issue arises with owl carousel elements not functioning properly when added dynamically through ajax calls and jquery

The owl carousel items seem to be facing an issue when added dynamically using AJAX and jQuery. Here is the AJAX code snippet, any assistance would be highly appreciated. Thank you in advance! $.ajax({ type: "POST", url: "urllinks", data: &a ...

Assigning attributes to each letter in a pangram

I am attempting to assign the appropriate class to a group of elements, representing each letter in the alphabet. The elements have IDs ranging from #alpha_0 to #alpha_25. If a letter appears just once in the input, it should be displayed in green. If a le ...

Any suggestions on how to repair this Node.js login interface?

Currently grappling with setting up a Node.js application with a MySQL database to create a basic login functionality. Encountering an issue: Cannot POST /login <body class="hero-image"> <div id="container"> <div ...

Arranging the navigation bar at the top of my chatbot in HTML

Is there a way to position the navigation bar above the chatbot on my website? The following CSS code excerpt is from the "navigation bar css" file: *{ padding: 0; margin: 0; text-decoration: none; list-style: none; box-sizing: border ...

Implementing Material-UI’s FlatButton and Dialog in ReactJS for dynamic TableRow functionality

I am working with Material-UI and have implemented a <Table> component. Each dynamically rendered <TableRow> in the <TableBody> needs to include a button (<FlatButton>) within one of the columns. When this button is clicked, a <D ...