So I’m using bootstrap and managed to center it but when I changed my resoluton/make it smaller the button wrapped and moved to the right a bit, Can anyone tell me what did I do wrong with it?
--HTML--
<div class="d-grid gap-2 col-2 mx-auto text-center">
<button id="Get" class="btn btn-outline-success btn-lg" type="button">Newest Upload</button> </div>
--CSS--
#Get {
border-width: 4px;
font-family: Lexend;
}
I tried to center it and it worked on bigger resolution but moved to the left when it’s on mobile resolution
2
Answers
You can try adding relative positioning
position: relative
to the parent<div>
, and then add absolute positioningposition: absolute
to the button, along withleft: 50%; top: 50%; transform: translate(-50%, -50%);
.This way, the position of the button will be independent of the resolution and screen size.Hope to be able to solve your problem.
To fix this, you can use the mx-auto class to center the button horizontally, regardless of the width of the columns. Here is the updated HTML code: