How to ensure buttons appear centered on different computer resolutions
P粉974462439
2023-08-13 18:51:08
<p>Mobile Resolution</p>
<p>So I'm using bootstrap and successfully center it, but when I change the resolution/zoom it out the buttons wrap and move slightly to the right, can anyone tell me what I'm doing wrong? </p>
<pre class="brush:php;toolbar:false;">--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">Latest upload</button> </div>
--CSS--
#Get {
border-width: 4px;
font-family: Lexend;
}</pre>
<p>I tried to center it, it works for larger resolutions but is shifted to the left on mobile resolutions</p>
You can try adding relative positioning
position: relative
to the parent<div>
and then adding absolute positioningposition: absolute
to the button, And addleft: 50%; top: 50%; transform: translate(-50%, -50%);
.This way, the button's position will be independent of resolution and screen size. Hope this solves your problem.