tag.
Examples of the Use of CSS Vertical-Align
Almost all cases of the use of CSS vertical-align involve vertically centering text next to an image. This style can affect just one image or several images contained within the “box” area defined by a block level element. You could also use this property to vertically align all of the images (child elements) within all of the tags (block level) on a page if that’s what you wanted. The block level element might be thought of as the “parent.” Remember that the style must be applied to the child or inline tag and not to the block level one in order to work. For example, if you want to vertically center some text next to an image, you would apply this property to the tag, not to the block level tag that contains that image tag.
In the example code below, you can see that I have three images, each contained separately within the tags. I could have put all of them within one set of tags and used the line-break tag to “stack” them one on top of the other, but I simply wanted to use the easiest way to space them for this example. The screen shots that follow show the results of using the “middle” value for CSS vertical-align and also the “top” value. It’ll be difficult to actually see the subtle differences between some of the available values for this property such as “baseline” (the default) and “sub,” but there is a difference if you look closely. Some of the other values you can use are “super” and “text-top.”
The Code Behind the Style


Examples Not Involving Images
So, if you don’t use the example of vertically aligning text next to an image, what other one could you use? You can also see this CSS style in action if you vertically align text next to a text box for instance. The cases in which you’d want to do this are probably rare, but there might be a time when you need or want to. Instead of applying the style to the tag, you would apply CSS vertical-align to the inline
There are also times when you need to vertically center text that isn’t next to an image or something visual like a text box. Unfortunately, that requires using different techniques because the vertical-align property won’t work. Some web designers resort to the use of invisible images or they manipulate line height to achieve vertical centering. Although tables should no longer be used to control layout, front-end development can be a headache when working with CSS. This is one of the reasons it’s very important to comment your code
; you’ll be able to quickly refresh your memory regarding the techniques, and sometimes hacks that you used. If you’d rather avoid intense CSS coding, yet would like stylish web pages, you might want to read Simple and Free CSS Templates.
Keep Exploring
More from Tech
Still writing your password on sticky notes? Do you use the same password for multiple sites? Why not use a password …
Do you have a limited data cap for your internet connection or are tired of seeing endless ads on your computer? …
Adblock Plus is obviously having an impact on Facebook’s revenues as Facebook recently changed the way they code ads on …
|