Position arrow from a dropdown menu correctly

Asked

Viewed 1,765 times

5

I added an arrow to my dropdown menus from Bootstrap 3, but I’m having trouble positioning Arrow correctly below the dropdown-toggle, below is a demo image:

Na esquerda é o meu cenário atual, com a arrow mal posicionada. Na direita é como eu gostaria de deixar.

On the left is my current scenario, with Arrow poorly positioned (right: 45%). On the right is how I’d like to leave.

Can anyone help me in this? Below my CSS code:

.dropdown-menu:before {
    position: absolute;
    top: -7px;
    right: 45%;
    display: inline-block;
    border-right: 7px solid transparent;
    border-bottom: 7px solid #ccc;
    border-left: 7px solid transparent;
    border-bottom-color: rgba(0, 0, 0, 0.2);
    content: '';
}

.dropdown-menu:after {
    position: absolute;
    top: -6px;
    right: 45%;
    display: inline-block;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #ffffff;
    border-left: 6px solid transparent;
    content: '';
}

1 answer

2

I once had this problem too. What I did was just change the property 'right: __'.

It determines the distance of the object from the right side, in this case it is 45% away from the right edge. Try to decrease until you get the result you want. I believe that with 'right:10%;' you achieve the desired result.

I hope I’ve helped.

Edit: If you want greater precision, you can use 'px' instead of '%'.

For imagine this: on a small and large screen he will be '10%' away from the side, but this % is different on a mobile phone and on a monitor 1080p. Already with the value in px it will be constant in all resolutions.

Then you can also use: 'right:15px' or another value giving the desired result.

  • @Cersuumt Gave an edited reply because it seems to me to be a reply indeed, and not just a comment. :)

  • 1

    Okay, thank you =D I also improved the explanation a little, I forgot to mention the purpose of the 'px''

  • Thanks for the help, @celsomtrindade. A few days ago I also took this "solution", I’m putting css inline right: x% in every dropdown I make, but I don’t intend to continue this for long.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.