Skip to content
Advertisement

Position child element directly under and justified right to the parent element

I am creating a dropdown menu component using React. I would like to know the CSS required to position the menu element directly under the “.menu-trigger” button, with its right border aligned to its parent’s (“.menu-container”), right border. I would like this CSS to be able to position a menu element of any reasonable size like this.

I believe I want to position the “.menu” component absolutely, relative to the parent, “.menu-container”, element.

Below is a stripped down version of html and css:

JavaScript

**** Edit ****

Solved using flexbox solution:

JavaScript

Advertisement

Answer

Here’s how to right-align using flexbox:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement