Vertical alignment of text in a block

A way to vertically align text in blocks of fixed height. The text is wrapped in a tag with a .child class, followed by an empty tag with a .helper class.

It is important that there are no spaces and line breaks between tags, as shown in the example:

<div><span class="child">Text to be aligned</span><span class="helper"></span></div>
HTML

CSS styles:

/* Vertical alignment */
.child {
	display: inline-block;
	vertical-align: middle;
	zoom: 1;
}
.helper {
	display: inline-block;
	vertical-align: middle;
	height: 100%;
	width: 0px;
	zoom: 1;
}
CSS
07.12.2016, updated 27.05.2021
30

Comments

to add a comment.

Other publications

CSS styles for horizontal lines
Collection of horizontal lines with hr tag of different types and styles.
61
0
Heading with a horizontal line in the middle
One way to make a heading with a horizontal line in the center without an image (background-image).
52
0
The viewport meta tag
Initially, the viewport meta tag appeared in the mobile version of Safari, then it was picked up by other developers and mobile browsers, although it is not part of the W3C standard.
34
0
Styling Checkbox
Here are some examples of how to change the look of checkboxes using CSS, images and some JS.
167
0
Smooth background change
This effect can be easily done through the CSS transition property for example buttons, menus, etc.
141
0
Connecting fonts in CSS
If you do not delve into the details, you can quickly connect the font like this ...
78
0