Search code examples
htmlbuttonvertical-alignmentmargins

Margin-Top is not working for me when attempting to adjust the location of a button


Margin-top seems to not be working for me. Margin-left is working completely fine. However, when I use margin-top nothing moves. I am trying to move a button vertically (upwards). When i tried using martin-top for a piece of text, it worked completely fine.

I've tried moving and re-formatting the code in several different ways.

<a style="margin-left:1180px;margin-top:-310px"><button onclick="myFunction()">Click me</button></a>

I expect margin-top to move the button 310 pixels upwards,but it remains static in the same position.


Solution

  • Just give display:block. It will work

    <a style="display:block;margin-left:1180px;margin-top:310px;"><button onclick="myFunction()">Click me</button></a>