Q:

How to Right Align Flex Item Using CSS

0

How to Right Align Flex Item Using CSS

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the CSS margin-left Property

You can simply use the CSS margin-left property with the value auto to right align flex item within a flex container. Please note that all child elements of flex container automatically become flex items.

The last item in the following example having the class .ml-auto will be automatically aligned to the right side. Let's try it out to understand how it basically works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Right-align Flex Item Using CSS</title>
<style>
.flex-container {		
    display: flex;
    background: #eee;
}
.item {
    padding: 10px;
}
.ml-auto {
    margin-left: auto;
}
</style>
</head>
<body>
    <div class="flex-container">
        <div class="item"><a href="#">Home</a></div>
        <div class="item"><a href="#">About</a></div>
        <div class="item"><a href="#">Services</a></div>
        <div class="item ml-auto"><a href="#">Login</a></div>
    </div>
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

HTML / CSS Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Center a DIV Horizontally and Vertically Us... >>
<< How to Make a DIV Vertically Scrollable Using CSS...