Home > Mobile >  Right Aligning Text with CSS
Right Aligning Text with CSS

Time:06-19

HTML

<body>
        <div >
            <h1>My Heading</h1>
            <nav>
                <a>Item 1</a>
                <a>Item 2</a>
                <a>Item 3</a>
                <a>Item 4</a>
            </nav>
        <div>
</body>

CSS

.menu_items nav a
{
    display: inline;
    margin-right: 10px;
    text-align: right;
}

This does not appear to move the menu_items to the right side of the page. What am I doing wrong?

CodePudding user response:

One way to achieve that is to move the text-align to .menu_items nav

.menu_items nav {
  text-align: right;
}

CodePudding user response:

You need to put text-align: right on the parent container - in this case the nav tag, not on the individual tags if you want them to align to the right.

nav {
    text-align: right;
}

  •  Tags:  
  • css
  • Related