

Lines already vertically center text, so by increasing the line height to that of the container's height, we can center the test. To align text vertically within a container, all you have to do is set the line-height of the container to be equal to the height. The container of the element must be set to position:relative or else the element will be centered relative to the body and not the container.Ĭentering text relative to a container is very easy and only requires the container to contain text-align:center.īy using the same concept as in method 3 of centering inline-block elements horizontally, we set the position of the element to absolute and move the top side to the middle of the page, we then move it back by half the element's width which will center it relative to its container as long as the container is either the body or a container with position:relative. If the element you wish to center is not a direct child of the body element, Then by using transform, we can move the element left by half of its width which will center the element in its container. By setting the position to absolute and left to 50%, we move the left side of the element to the middle of the page. This method is the most complicated of the 3 but it is the most effective, with no obvious disadvantages. The problem with using this method is that it may not always be desirable to have a flexible width. This method will also work on block elements. This is the easiest method but it comes with the problem that any other elements that are children of the container will also be centered.īy using a percentage for the width, we can set the left margin of the element to half of what is left when we subtract the width from 100%, this will center the element. The block element must be given an absolute width for this method to work, if this is not desired, method 2 and 3 below for centering inline-block elements will work on block elements as well.īy using text-align:center on the container of the inline-block element you wish to center (in this case the body) any inline or inline-block elements will be centered. You can set the Y margin (which is 0 in this case) to whatever value you need. All that must be done is to set the X margin to auto which will center it. Select the cell or cells in the table and type your text.Centering element and text can be quite difficult for new developers but is definitely a worthwhile skill to learn as it does come in handy very often.īlock level elements are the easiest elements to center.Make a table inside your Word document.Without any further ado, below are the steps to type text and make it flow vertically in Word. With some settings, you can type text that flows vertically in the table cells. When working with tables in Microsoft Word, the text must not always flow from left to right. NOTE: Use this same method discussed above to type text vertically in Word using text boxes. To make the text more apparent, adjust the shape afterward. The size of the shape will automatically change to accommodate your text as you change the direction. If you are not satisfied with the 90° or 270° option, click on the Text Direction Options for settings. Now go to the Drawing Tools > Format tab, under the text group, select the Text Direction drop-down button and choose the direction you want.Click on the shape containing the text.To change the text direction to vertical: Using the Text Direction command on the Ribbon
